GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing ja.javascript.info — 範囲でフィルタする

  • チュートリアル
  • JavaScript 言語
  • データ型
  • 配列のメソッド
レッスンに戻る

範囲でフィルタする

重要性: 4

配列 arr を取得し、a と b の間で要素を探し、それらの配列を返す関数 filterRange(arr, a, b) を書いてください。

この関数は配列を変更するべきではありません。新しい配列を返すべきです。

例:

let arr = [5, 3, 8, 1];

let filtered = filterRange(arr, 1, 4);

alert( filtered ); // 3,1 (マッチした値)

alert( arr ); // 5,3,8,1 (修正されていない)

テストと一緒にサンドボックスを開く

function filterRange(arr, a, b) {
  // added brackets around the expression for better readability
  return arr.filter(item => (a <= item && item <= b));
}

サンドボックスでテストと一緒に解答を開く

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.