728x90
// Filter Range
// Write a function filterRange(arr, a, b) that gets an array arr,
// looks for elements with values higher or equal to a and lower or equal to b and return a result as an array.
// !! The function should not modify the array. It should return the new array.
function filterRange(arr, a, b) {
return arr.filter(arr => (arr >= a && arr <= b));
}
const arr = [5, 3, 8, 1];
const filtered = filterRange(arr, 1, 4);
console.log( filtered ); // 3,1 (matching values)
console.log( arr ); // 5,3,8,1 (not modified)
view raw filterRange.js hosted with ❤ by GitHub

+ Recent posts