Skip to content

filter$

Subhajit Sahu edited this page Dec 5, 2022 · 16 revisions

Keep entries which pass a test.

Alternatives: filter, filter$.
Similar: map, reduce, filter, filterAt, reject, rejectAt.


function filter$(x, ft)
// x:  an map (updated)
// ft: test function (v, k, x)
const map = require('extra-map');

var x = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]]);
map.filter$(x, v => v % 2 === 1);
// → Map(3) { 'a' => 1, 'c' => 3, 'e' => 5 }

x;
// → Map(3) { 'a' => 1, 'c' => 3, 'e' => 5 }

var x = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]]);
map.filter$(x, v => v % 2 === 0);
// → Map(2) { 'b' => 2, 'd' => 4 }
Clone this wiki locally