Skip to content
Subhajit Sahu edited this page Dec 28, 2022 · 14 revisions

Keep first n entries only (default order).

Similar: take, drop.


function take(x, n)
// x: ilists
// n: number of entries [1]
const xilists = require('extra-ilists');

var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
xilists.take(x, 2).map(c => [...c]);
// → [ [ 'a', 'b' ], [ 1, 2 ] ]

xilists.take(x, 3).map(c => [...c]);
// → [ [ 'a', 'b', 'c' ], [ 1, 2, 3 ] ]


References

Clone this wiki locally