function flatten(list) { return list.reduce(function (acc, val) { return acc.concat(val.constructor === Array ? flatten(val) : val); }, []); }