Skip to content

partition

Subhajit Sahu edited this page Dec 8, 2022 · 8 revisions

Segregate entries by test result.

Similar: partition, partitionAs.
Similar: partition, chunk.


function partition(x, ft)
// x:  an object
// ft: test function (v, k, x)
const object = require('extra-object');

var x = {a: 1, b: 2, c: 3, d: 4};
object.partition(x, v => v % 2 == 0);
// → [ { b: 2, d: 4 }, { a: 1, c: 3 } ]

var x = {a: 1, b: 2, c: 3, d: 4, e: 5};
object.partition(x, v => v % 2 == 1);
// → [ { a: 1, c: 3, e: 5 }, { b: 2, d: 4 } ]


References

Clone this wiki locally