Skip to content

interleave

Subhajit Sahu edited this page Mar 22, 2020 · 17 revisions

Places values of an array between another.

array.interleave(x, y, [m], [n]);
// x: an array
// y: another array
// m: number of values from x (1)
// n: number of values from y (1)
const array = require('extra-array');

var x = [1, 2, 3, 4];
var y = [10, 20, 30];
array.interleave(x, [10]);
// [1, 10, 2, 10, 3, 10, 4]

array.interleave(x, y);
// [1, 10, 2, 20, 3, 30, 4]

array.interleave(x, y, 2);
// [1, 2, 10, 3, 4]

array.interleave(x, y, 1, 2);
// [1, 10, 20, 2, 30, 10, 3, 20, 30, 4]

references

Clone this wiki locally