1.0.0 • Published 4 years ago

interleave v1.0.0

Weekly downloads
57
License
MIT
Repository
-
Last release
4 years ago

Interleave arrays and other iterables, with full type support.

Examples

Interleaving an array:

import interleave from "interleave";

interleave(['a', 'b', 'c'], [1, 2]);
// Returns ['a', 1, 'b', 2, 'c']

// Also supports multiple arrays:
interleave(['a', 'b', 'c'], [1, 2, 3], ['A', 'B', 'C']);
// Returns ['a', 1, 'A', 'b', 2, 'B', 'c', 3, 'C']

Interleaving an iterable:

// This can be any iterable. String example:
interleave('abc', 'ABC');
// Returns ['a', 'A', 'b', 'B', 'c', 'C']

Other example use case using strings:

// You could join them into a string like this, using the .join() array method:
interleave('abc', 'ABC').join('');
// Returns 'aAbBcC'

Documentation

Method overloads:

  • interleave<T>(...arrays: T[][]): T[]
    • Interleaves multiple arrays.
  • interleave<T>(...iterables: Iterable<T>[]): T[]
    • Interleaves multiple iterators.

Both signatures do exactly the same thing, though the arrays implementation does not depend on iterators.

Edge Cases

  • Nothing is passed in
    • Returns an empty array
  • One array is passed in
    • Returns that array
  • Arrays/iterators are of different lengths * Elements of each array are interleaved until there are no more of that array, and other array/iterators will continue to be interleaved:
        ```
        interleave([1, 2, 3], [4, 5], [6, 7, 8])
        // Returns [1, 4, 6, 2, 5, 7, 3, 8]
        ```
    Edge cases have been tested with Jest. Jest tests are included in dist/index.test.js.
1.0.0

4 years ago

0.7.0

8 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.24

12 years ago

0.5.23

12 years ago

0.5.22

12 years ago

0.5.21

12 years ago

0.5.20

12 years ago

0.5.19

12 years ago

0.5.18

12 years ago

0.5.17

12 years ago

0.5.16

12 years ago

0.5.15

12 years ago

0.5.14

12 years ago

0.5.13

12 years ago

0.5.12

12 years ago

0.5.11

12 years ago

0.5.10

12 years ago

0.5.9

12 years ago

0.5.8

12 years ago

0.5.7

12 years ago

0.5.6

12 years ago

0.5.5

12 years ago

0.5.3

12 years ago

0.5.2

12 years ago

0.5.1

12 years ago

0.4.5

12 years ago

0.4.4

12 years ago

0.3.3

12 years ago

0.3.2

12 years ago

0.4.3

12 years ago

0.4.2

12 years ago

0.4.1

12 years ago

0.4.0

12 years ago

0.3.1

12 years ago

0.3.0

12 years ago

0.2.2

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.6

12 years ago

0.1.5

12 years ago

0.1.4

12 years ago

0.1.3

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.11

13 years ago

0.0.10

13 years ago

0.0.9

13 years ago

0.0.8

13 years ago

0.0.7

13 years ago

0.0.6

13 years ago

0.0.5

13 years ago

0.0.4

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago

0.0.1

13 years ago