Skip to content

Instantly share code, notes, and snippets.

View sstalin's full-sized avatar

Svetlin Stalinov sstalin

View GitHub Profile
@sstalin
sstalin / flatten.js
Created August 25, 2015 21:46
flatten nested array of arrays of integers in JavaScript
/**
* 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);
}, []);
};