2.2.10 • Published 4 years ago

@extra-lists/flat v2.2.10

Weekly downloads
16
License
MIT
Repository
github
Last release
4 years ago

Flattens nested lists to given depth. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Alternatives: flat, flatMap.

This is part of package extra-lists.

lists.flat(x, [n], [fm], [ft]);
// x:  nested lists
// n:  maximum depth (-1)
// fm: map function (v, k, x)
// ft: test function (v, k, x)
const lists = require('extra-lists');

var x = [['ab', 'cde'], [
  [['a', 'b'], [1, 2]],
  [['c', 'de'], [
    3,
    [['d', 'e'], [
      3,
      [['e'], [
        5
      ]]
    ]]
  ]]
]];
lists.flat(x).map(c => [...c]);
// [ [ 'a', 'b', 'c', 'd', 'e' ], [ 1, 2, 3, 3, 5 ] ]

lists.flat(x, 1).map(c => [...c]);
// [ [ 'a', 'b', 'c', 'de' ], [ 1, 2, 3, [ [Array], [Array] ] ] ]

lists.flat(x, 2).map(c => [...c]);
// [ [ 'a', 'b', 'c', 'd', 'e' ], [ 1, 2, 3, 3, [ [Array], [Array] ] ] ]

References

2.2.10

4 years ago

2.2.9

4 years ago

2.2.8

4 years ago

2.2.7

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.0

4 years ago

2.1.3

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.91

4 years ago

2.0.90

4 years ago

2.0.89

4 years ago

2.0.88

4 years ago