take - nodef/extra-lists GitHub Wiki

Keep first n entries only (default order).

Similar: take, drop.

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

var x = ['a', 'b', 'c', 'd'], [1, 2, 3, 4](/nodef/extra-lists/wiki/'a',-'b',-'c',-'d'],-[1,-2,-3,-4);
xlists.take(x, 2).map(c => [...c]);
// → [ [ 'a', 'b' ], [ 1, 2 ] ]

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

References