interleave-array
v1.0.1
Published
interleave values from arrays
Downloads
10
Readme
interleave-array
interleaves values from arrays into a new array
examples
var interleave = require('interleave-array')
interleave(['a', 'b', 'c'], [1, 2, 3])
// => ['a', 1, 'b', 2, 'c', 3]
it also works with more than two arrays and different types of objects:
interleave([[1, 2], [3, 4], [5, 6]],
[{a: 1}, {b: 2}, {c: 3}]
['cat', 'dog', 'bird']
// => [[1, 2], {a: 1}, 'cat', [3, 4], {b: 2}, 'dog', [5, 6], {c: 3}, 'bird']
interleaving is truncated at the length of the shortest provided array. for example:
interleave([1, 3], [2])
// => [1, 2]
see also
loose-interleave
is similar but does not truncate to shortest.
license
MIT