-
Notifications
You must be signed in to change notification settings - Fork 1
range
Subhajit Sahu edited this page Feb 3, 2021
·
15 revisions
Finds smallest and largest entries. 🏃 📼 📦 🌔 📒
map.range(x, [fc], [fm]);
// x: a map
// fc: compare function (a, b)
// fm: map function (v, k, x)
// --> [smallest, largest]
const map = require("extra-map");
var x = new Map([["a", 1], ["b", 2], ["c", -3], ["d", -4]]);
map.range(x);
// [ [ "d", -4 ], [ "b", 2 ] ]
map.range(x, (a, b) => Math.abs(a) - Math.abs(b));
// [ [ "a", 1 ], [ "d", -4 ] ]
map.range(x, null, v => Math.abs(v));
// [ [ "a", 1 ], [ "d", -4 ] ]