interleave-array

1.0.1 • Public • Published

interleave-array

Build Status npm install npm version js-standard-style License

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

Readme

Keywords

Package Sidebar

Install

npm i interleave-array

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • jarofghosts