simontonsoftware / s-libs

A collection of libraries for any of javascript, rxjs, or angular.
MIT License
43 stars 5 forks source link

[micro-dash] Feature request: `pullAllBy()` #62

Closed ersimont closed 3 years ago

ersimont commented 3 years ago

First stab:

function pullAllBy<T>(array: T[], match: (val: T) => boolean): T[] {
  const pulled: T[] = [];
  for (let i = 0; i < array.length;) {
    const val = array[i];
    if (match(val)) {
      array.splice(i, 1);
      pulled.push(val);
    } else {
      ++i;
    }
  }
  return pulled;
}
ersimont commented 3 years ago

Never mind. remove() is what I actually wanted.