rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
22 lines • 602 B
JavaScript
/**
* @public
* Removes each item in `itemsToRemove` from `items` (including any repeated items).
*
* @returns The number of items that were removed.
*
* @remarks
* See {@link arrayRemoveMany}.
*/
export function arrayRemoveMany(items, itemsToRemove) {
const setOfItemsToRemove = new Set(itemsToRemove);
let index = items.length;
let removedItems = 0;
while (index-- > 0) {
if (setOfItemsToRemove.has(items[index])) {
items.splice(index, 1);
++removedItems;
}
}
return removedItems;
}
//# sourceMappingURL=array-remove-many.js.map