RosettaCodeData/Task/Flatten-a-list/JavaScript/flatten-a-list-6.js

9 lines
168 B
JavaScript
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
// flatten :: NestedList a -> [a]
2019-09-12 10:33:56 -07:00
const flatten = t => {
2020-02-17 23:21:07 -08:00
const go = x =>
Array.isArray(x) ? (
x.flatMap(go)
) : x;
2019-09-12 10:33:56 -07:00
return go(t);
};