Transformation of a flat array into multidimensional | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 16

Transformation of a flat array into multidimensional

I have such array: let mdarr = [ true, -Infinity, NaN, undefined, "4rontender", {"lol": [ 0, 1, 2 ] } ]; something like this in the output: -> [ [ [ true, [ -Infinity, NaN ] ] ], [ undefined, ["4rontender", [ {"kek": [ 2, 1, 0 ] } ] ] ] ]; // hint: mdarr = [ Array(1), Array(2) ] Is it realistic to do this? And what is the fastest and most optimal solution? Thanks:-)

5th Oct 2017, 11:31 AM
\__(° = °)__/
3 Answers
+ 10
Please, pay attention to the object of the resulting array: it was so: {"lol": [ 0, 1, 2 ] }, but it became so: {"kek": [ 2, 1, 0 ] }
5th Oct 2017, 11:34 AM
\__(° = °)__/
+ 9
you can reduce dimensions. but of course I need universal solution and with different data types, and most optimal😊
5th Oct 2017, 11:36 AM
\__(° = °)__/
+ 5
Always possible but I still don't know the pattern 😵
5th Oct 2017, 11:33 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar