Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

javascript関数ドリル 初級編without関数の実相のアウトプット

Last updated at Posted at 2020-09-10

##zipObject関数の課題内容
詳細はこちら
   ↓
https://js-drills.com/blog/without/

##zipObject関数の取り組む前の状態
スプレッド演算子を使う発想がなかった。includeメソットを知らなかった

##zipObject関数に取り組んだ後の状態
理解できた

##zipObject関数の実装コード(答えを見る前)
分からなかった

##zipObject関数の実装コード(答えを見た後)


function without(array, ...values) {
  const newArray = [];
  for(let i = 0; i < array.length; i++) {
    const candidateToPush = array[i];
    // values : [1, 2]
    // array: [2, 1, 2, 3]
    // candidateToPush: 2, 1, 2, 3
    if( !values.includes(candidateToPush) ) {
      newArray.push(candidateToPush);
    }
  }

  return newArray;
}

console.log( without([2, 1, 2, 3], 1, 2) );
// => [3]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?