MCPcopy Create free account
hub / github.com/activejs/activejs / removeIf

Method removeIf

packages/core/src/lib/list-unit.ts:235–247  ·  view source on GitHub ↗

* Removes items from the list-value where the predicate returns `truthy` value. \ * Dispatches a new copy of the value, without mutating the current-value. \ * It modifies the length of the list as these indices are not deleted, * rather removed using `Array.prototype.splice`. *

(predicate: (item: Item, index: number) => boolean)

Source from the content-addressed store, hash-verified

233 * @category Custom ListUnit
234 */
235 removeIf(predicate: (item: Item, index: number) => boolean): Item[] {
236 if (this.isFrozen || typeof predicate !== 'function' || this.isEmpty) {
237 return [];
238 }
239
240 const indicesToBeRemoved = [];
241 this.value().forEach((item, index) => {
242 if (predicate(item, index)) {
243 indicesToBeRemoved.push(index);
244 }
245 });
246 return this.remove(...(indicesToBeRemoved as [number, ...number[]]));
247 }
248
249 /**
250 * Deletes items at given indices in the list-{@link value}. \

Callers 3

utils.tsFile · 0.80
list-unit.spec.tsFile · 0.80
removeCompletedMethod · 0.80

Calls 4

removeMethod · 0.95
predicateFunction · 0.85
pushMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected