• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

87
Views
Should I use map/reduce/flatten functions to manipulate Multi-Dimensional Array in Javascript

I have this data :

[
["A","X1","Y1"],
["A","X2","Y2"],
["A","X3","Y3"],
["B","X4","Y4"],
["B","X5","Y5"],
["B","X6","Y6"],
]

and would like to change the array structure to be this :

[
["A",["X1","Y1"],["X2","Y2"],["X3","Y3"]],
["B",["X4","Y4"],["X5","Y5"],["X6","Y6"]],
]

I have been playing around with flatten function (flatten with a 'key' (i.e A and B) and then join all back together at the end.) - but the 'key' change from A to B (and potentially to C, D, E ....) has got me stumped.

I would appreciate any pointers as to the most efficient direction to go. Has any one else met this type of need ? Is there a better way (outside nested interations)

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error