Created
August 13, 2019 14:12
-
-
Save lancevo/ac2702b300b7613dc7c404f8ee9742b1 to your computer and use it in GitHub Desktop.
Revisions
-
Lance Vo created this gist
Aug 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ function filterInPlace(array, condition) { let iOut = 0; for (let i = 0; i < array.length; i++) { if (condition(array[i])) { array[iOut++] = array[i]; } } array.length = iOut; } const arr = []; for (let i = 0; i<100; i++) { arr.push(i); } filterInPlace(arr, (n) => n % 2); // [0,2,4,6...]