Merge pull request #756 from maurodibert/patch-22

solution out of the tutorial
This commit is contained in:
Ilya Kantor 2019-01-27 19:34:12 +03:00 committed by GitHub
commit e774c7c938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,22 @@
``` js run
function filterRangeInPlace(arr, a, b) {
for (let i = 0; i < arr.length; i++) {
let val = arr[i];
// remove if outside of the interval
if (val < a || val > b) {
arr.splice(i, 1);
i--;
}
}
}
let arr = [5, 3, 8, 1];
filterRangeInPlace(arr, 1, 4); // removed the numbers except from 1 to 4
alert( arr ); // [3, 1]
```