[ Web Proxy ]
URL:
Viewing: https://ko.javascript.info/task/filter-through-function [Back]  [Original]

:
Light themeDark theme
DanskEnglishEspaolFranaisIndonesiaItalianoTrkeOzbek

: 5

arr.filter(f) f true .

filter .

  • inBetween(a, b) a b
  • inArray([...])

.

  • arr.filter(inBetween(3,6)) 3 6
  • arr.filter(inArray([1,2,3])) [1,2,3]

:

/* ...    inBetween inArray  ...*/
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

.


Web Proxy Viewer  |  New URL  |  Original Page