Sha256: 99a643304b0e93e6ef99070647e569c21cc1097af1e0a930416e98b045f3e7f1
Contents?: true
Size: 515 Bytes
Versions: 35
Compression:
Stored size: 515 Bytes
Contents
module.exports = function flatten(list, depth) { depth = (typeof depth == 'number') ? depth : Infinity; if (!depth) { if (Array.isArray(list)) { return list.map(function(i) { return i; }); } return list; } return _flatten(list, 1); function _flatten(list, d) { return list.reduce(function (acc, item) { if (Array.isArray(item) && d < depth) { return acc.concat(_flatten(item, d + 1)); } else { return acc.concat(item); } }, []); } };
Version data entries
35 entries across 34 versions & 12 rubygems