Skip to content

intersperse

Subhajit Sahu edited this page May 10, 2020 · 14 revisions

Places a separator between every value. 🏃 📼 📦 🌔

Similar: interleave, intersperse.

iterable.intersperse(x, v);
// x: an iterable
// v: separator
const iterable = require('extra-iterable');

var x = [1, 2, 3];
[...iterable.intersperse(x, 10)];
// [ 1, 10, 2, 10, 3 ]

var x = [1, 2, 3, 4];
[...iterable.intersperse(x, 10)];
// [ 1, 10, 2, 10, 3, 10, 4 ]

references

Clone this wiki locally