JAVASCRIPT   19

removeAll.js

Guest on 28th May 2021 03:32:25 AM

  1. var indexOf = require('./indexOf');
  2.  
  3.     /**
  4.      * Remove all instances of an item from array.
  5.      */
  6.     function removeAll(arr, item){
  7.         var idx = indexOf(arr, item);
  8.         while (idx !== -1) {
  9.             arr.splice(idx, 1);
  10.             idx = indexOf(arr, item, idx);
  11.         }
  12.     }
  13.  
  14.     module.exports = removeAll;

Raw Paste


Login or Register to edit or fork this paste. It's free.