Created
October 12, 2016 20:08
-
-
Save jasonwaters/ffa6a642c7a6a6c940a770c620707433 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
var a = [1, {a: [2, [3]]}, 'four', [[5], [6]], [[7], 8, 9], 10]; | |
function flatten(arr) { | |
let idx = 0; | |
while(idx < arr.length) { | |
if(arr[idx] instanceof Array) { | |
Array.prototype.splice.apply(arr, [idx, 1].concat(arr[idx])); | |
}else { | |
idx++; | |
} | |
} | |
} | |
flatten(a); | |
console.log(a); |
Author
jasonwaters
commented
Jan 27, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment