Skip to content

partition

Subhajit Sahu edited this page Feb 4, 2021 · 13 revisions

Segregates values by test result. 📦 😺 🏃 📼 🌔 📜 📰 📘

Alternatives: partition, partitionAs.


entries.partition(x, ft);
// x:  entries
// ft: test function (v, k, x)
// → [satisfies, doesnt]
const entries = require("extra-entries");

var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4]];
entries.partition(x, v => v % 2 == 0).map(x => [...x]);
// [ [ [ "b", 2 ], [ "d", 4 ] ], [ [ "a", 1 ], [ "c", 3 ] ] ]

var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4], ["e", 5]];
entries.partition(x, v => v % 2 == 1).map(x => [...x]);
// [ [ [ "a", 1 ], [ "c", 3 ], [ "e", 5 ] ], [ [ "b", 2 ], [ "d", 4 ] ] ]


References

Clone this wiki locally