leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2634.js (268B)


      1 /**
      2  * @param {number[]} arr
      3  * @param {Function} fn
      4  * @return {number[]}
      5  */
      6 
      7 var filter = function(arr, fn) {
      8     var j = 0;
      9     for(let i = 0; i < arr.length; i++)
     10       if(fn(arr[i], i)) arr[j++] = arr[i];
     11     while (arr.length > j) arr.pop();
     12     return arr;
     13 };