Skip to content

takeWhile

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

Extracts values till a test passes. 🏃 📼 📦 🌔 📒

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

array.takeWhile(x, fn, [ths]);
// x:   an array
// 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