This file contains hidden or 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
function flatten(arr) { | |
if (Array.isArray(arr)) { | |
return arr.reduce(function(done,curr){ | |
return done.concat(flatten(curr)); | |
}, []); | |
} else { | |
return arr; | |
} | |
} |
This file contains hidden or 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 flat = arr.reduce(function(done,curr){ | |
return done.concat(curr); | |
}, []); | |
// [ 1, 2, 3, [ [ 4 ] ] ] |
NewerOlder