N
N
Nick Bukovskiy2020-06-05 11:28:01
Algorithms
Nick Bukovskiy, 2020-06-05 11:28:01

How to sort an array so as to turn it into a tree structure?

const variants = [
  ['0', 'Slate', 'Single'],
  ['1', 'Slate', 'Single'],
  ['2', 'Slate', 'Single'],
  ['3', 'Slate', 'Single'],
  ['4', 'Slate', 'Single'],
  ['5', 'Slate', 'Single'],
  ['0', 'Slate', '3-Pack'],
  ['1', 'Slate', '3-Pack'],
  ['2', 'Slate', '3-Pack'],
  ['3', 'Slate', '3-Pack'],
  ['4', 'Slate', '3-Pack'],
  ['5', 'Slate', '3-Pack']
]


There is such an array. You need to sort it in such a way that you get type options:
0 - Slate is available for it and Single and 3-Pack are available for it,
and thus make the structure so that, depending on the selected one, the following options are displayed

I will be glad for any advice or help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayton2019, 2020-06-09
@mayton2019

The author, well, you set motivating tasks. All data structures are with anonymous fields. So how do you write an algorithm? There is a tuple with three fields. The first field is without a name .. the second is without a name.
I could at least make an effort to get it done.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question