-
Notifications
You must be signed in to change notification settings - Fork 3
partition
Subhajit Sahu edited this page Jun 11, 2020
·
8 revisions
Segregates values by test result. 🏃 📼 📦 🌔 📒
Alternatives: partition, partitionAs.
object.partition(x, fn, [ths]);
// x: an object
// fn: test function (v, k, x)
// ths: this argument
// --> [satisfies, doesnt]
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 } ]