Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript filter in place algorithm

function filterInPlace(a, condition) {
  let i = 0, j = 0;

  while (i < a.length) {
    const val = a[i];
    if (condition(val, i, a)) a[j++] = val;
    i++;
  }

  a.length = j;
  return a;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #filter #place #algorithm
ADD COMMENT
Topic
Name
3+4 =