solution outside the tutorial
This commit is contained in:
parent
8c1782b50c
commit
30d62b78ca
1 changed files with 14 additions and 0 deletions
|
@ -0,0 +1,14 @@
|
||||||
|
``` js run
|
||||||
|
function filterRange(arr, a, b) {
|
||||||
|
// added brackets around the expression for better readability
|
||||||
|
return arr.filter(item => (a <= item && item <= b));
|
||||||
|
}
|
||||||
|
|
||||||
|
let arr = [5, 3, 8, 1];
|
||||||
|
|
||||||
|
let filtered = filterRange(arr, 1, 4);
|
||||||
|
|
||||||
|
alert( filtered ); // 3,1 (matching values)
|
||||||
|
|
||||||
|
alert( arr ); // 5,3,8,1 (not modified)
|
||||||
|
```
|
Loading…
Add table
Add a link
Reference in a new issue