Need help with solving this problem

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.

What have you tried so far? What results have you gotten?

let filtered = arr.slice(a, b);

Tried that but I was way off. I think I need to use filer(), but have yet to figure out how.

That would be along the lines of what you want if a and b were indexes, but it sounds like you need to check the values of the elements in arr.

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. :+1:t3: