Skip to content
Subhajit Sahu edited this page Jun 15, 2020 · 27 revisions

Keeps the values which pass a test. 🏃 📼 📦 🌔 📒

Alternatives: filter, [filterAt].
Similar: map, filter, [reject], reduce, accumulate.

iterable.filter(x, fn);
// x:  an iterable
// fn: test function (v, i, x)
const iterable = require('extra-iterable');

var x = [1, 2, 3, 4, 5];
[...iterable.filter(x, v => v % 2 === 1)];
// [ 1, 3, 5 ]

[...iterable.filter(x, v => v % 2 === 0)];
// [ 2, 4 ]

references

Clone this wiki locally