function filterRange(arr, a, b){
// gets an array arr, looks for elements between a and b in it and returns an array of them.
// The function should not modify the array. It should return the new array.
}
/*
example:
let arr = [5, 3, 8, 1];
let filtered = filterRange(arr, 1, 4);
filtered; // 3,1 (matching values)
*/
Please I just want ways in going about solving it like with examples. I know i can google for
the solution, but I want to try and solve it myself first.
Hi. With arr.slice() you’d be manipulating the array with respect to index. What you have to do is, iterate through the array, compare the numbers with the parameters and then form a new array with the values that pass the condition.
There are a lot of ways to do it. Try it. And let us know if you need more help with this.