当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

flatten

优质
小牛编辑
141浏览
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);
}
NameType(s)Description
shallowboolean

Option to flatten only one level deep (default is recursive).

returnsSequence

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]