: 5
arr.filter(f) . f . true .
:
inBetween(a, b)ab( ).inArray([...]).
:
arr.filter(inBetween(3,6))3 6 .arr.filter(inArray([1,2,3]))[1,2,3].
:
/* .. inArray inBetween */
let arr = [1, 2, 3, 4, 5, 6, 7];
alert( arr.filter(inBetween(3, 6)) ); // 3,4,5,6
alert( arr.filter(inArray([1, 2, 10])) ); // 1,2
Filter inBetween
Filter inBetween
function inBetween(a, b) {
return function(x) {
return x >= a && x <= b;
};
}
let arr = [1, 2, 3, 4, 5, 6, 7];
alert( arr.filter(inBetween(3, 6)) ); // 3,4,5,6
Filter inArray
Filter inArray
function inArray(arr) {
return function(x) {
return arr.includes(x);
};
}
let arr = [1, 2, 3, 4, 5, 6, 7];
alert( arr.filter(inArray([1, 2, 10])) ); // 1,2
function inArray(arr) {
return x => arr.includes(x);
}
function inBetween(a, b) {
return x => (x >= a && x <= b);
}