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 to flatten array of arrays of integers using recursion and Array.prototype.reduce. | |
* @param {Array} an input array of arrays of integers | |
* @returns {Array} flatten array of integers | |
*/ | |
function flatten(arr){ | |
return arr.reduce(function (prev, curr) { | |
return prev.concat(curr.constructor === Array ? flatten(curr) : curr); | |
}, []); | |
}; |