Created
May 23, 2017 19:03
-
-
Save AWattNY/838cec8e84234859beec33a10bf42f68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Test Case 1 | |
//input >>>>>[1,4,2,4, [8, 10, 7], 3, [2, 12]] | |
// output >>>>> [1, 4, 2, 4, 8, 10, 7, 3, 2, 12] | |
//Test Case 2 | |
// //input >>>>>[1, 4, 2, 4, [8, [10, 57, 61], 7], 3, [2, 12]] | |
// output >>>>> [ 1, 4, 2, 4, 8, 10, 57, 61, 7, 3, 2, 12 ] | |
//Test Case 3 | |
// //input >>>>>[1, 4, 2, 4, [8, [10, [57, 108, 950], 61], 7], 3, [2, 12]] | |
// output >>>>> [ 1, 4, 2, 4, 8, 10, 57, 108, 950, 61, 7, 3, 2, 12 ] | |
const processArray = (array) => { | |
return array.reduce((accu, curr) => { | |
accu = ( Array.isArray(curr) ) ? accu.concat(processArray(curr)) : accu.concat(curr); | |
return accu; | |
}, []); | |
}; | |
console.log(processArray([1, 4, 2, 4, [8, [10, [57, 108, 950], 61], 7], 3, [2, 12]])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment