Skip to content

takeWhile

Subhajit Sahu edited this page May 19, 2020 · 15 revisions

Extracts values till a test passes. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]

Alternatives: [take], [takeWhile].
Similar: [take], [drop].

iterable.takeWhile(x, fn, [ths]);
// x:   an iterable
// fn:  test function (v, i, x)
// ths: this argument
const array = require('extra-array');

var x = [1, 2, 3, 4, 5];
array.takeWhile(x, v => v < 3);
// [ 1, 2 ]

array.takeWhile(x, v => v < 4);
// [ 1, 2, 3 ]

references

Clone this wiki locally