flatten
优质
小牛编辑
136浏览
2023-12-01
Creates a new sequence with every element from this sequence, and with arrays exploded so that a sequence of arrays (of arrays) becomes a flat sequence of values.
Signature
Sequence.flatten = function(shallow) { /*...*/ }
Sequence.flatten = function flatten(shallow) { return new FlattenedSequence(this, shallow); }
Name | Type(s) | Description |
---|---|---|
shallow | boolean | Option to flatten only one level deep (default is recursive). |
returns | Sequence | The new sequence. |
Examples
Lazy([1, [2, 3], [4, [5]]]).flatten() // sequence: [1, 2, 3, 4, 5] Lazy([1, [2, 3], [4, [5]]]).flatten(true) // sequence: [1, 2, 3, 4, [5]] Lazy([1, Lazy([2, 3])]).flatten() // sequence: [1, 2, 3]