728x90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function inBetween(a, b) { | |
return function(x) { | |
return x >= a && x <= b; | |
} | |
} | |
function inArray(arr) { | |
return function(x) { | |
return arr.includes(x); | |
} | |
} | |
const arr = [1, 2, 3, 4, 5, 6, 7]; | |
console.log( arr.filter(inBetween(3, 6)) ); // 3, 4, 5, 6 | |
console.log( arr.filter(inArray([1, 2, 10])) ); // 1, 2 |