Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

need help in nested array concatenaton/appending operation concept

i have three arrays. H, E, and F.

const H = [
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
    [$, _, _, _, _, _, _, $,],
]

const E = [
    [$, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, $, $, $, $, $, $, $,],
]

const F = [
    [$, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, _,],
  ];

i want following output: H E F which is:

[
    [$, _, _, _, _, _, _, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $, $,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, _, _, _, _, _, _, _, $, _, _, _, _, _, _, _,],
    [$, _, _, _, _, _, _, $, $, $, $, $, $, $, $, $, $, _, _, _, _, _, _, _,],
]

basically i want to combine HEF from H,E,F. any solution through looping or maybe if lodash provide this functionality? as this is array in array im open to looping solutions and any lodash or maybe if any javascript library provide this functionality then let me know.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Looks like you just need to apply concat to each row separately:

a = [
    ['a','b','c'],
    ['d','e','f'],
]
b = [
    ['g','h'],
    ['i','j'],
]
c = [
    ['k', 'l'],
    ['m', 'n'],
]


let glue = args => args[0].map(
    (_, i) => [].concat(
        ...args.map(a => a[i])))

result = glue([a, b, c])

console.log(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading