typedash
Version:
modern, type-safe collection of utility functions
19 lines (18 loc) • 726 B
JavaScript
//#region src/functions/partition/partition.ts
/**
* Implementation of all overloads.
* @param array The input array to partition.
* @param predicate A function that takes an array item and returns a boolean indicating whether the item should be included in the "equals" array or the "notEquals" array.
* @returns A tuple containing two arrays: the "equals" array and the "notEquals" array.
*/
function partition(array, predicate) {
if (array == null) return [[], []];
const equals = [];
const notEquals = [];
for (const item of array) if (predicate(item)) equals.push(item);
else notEquals.push(item);
return [equals, notEquals];
}
//#endregion
export { partition as t };
//# sourceMappingURL=partition-CxnPk1_S.js.map