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関数ドリル】 初級編join関数の実装

Posted at

##join関数の課題内容
「課題内容」「解説動画」「解答例」を確認したい場合は、以下リンク先のページを参照。     ↓
https://js-drills.com/blog/initial/

##join関数 に取り組む前の状態
joinメソット自体はどのようなもの知っていた

##join関数に取り組んだ後の状態
swiftメソットが配列のはじめを消すことが分かった
##join関数の実装コード(答えを見る前)
自力で実装できませんでした。
##join関数の実装コード(答えを見た後)

function join(array, separator = ',') {
  const copiedArray = [...array];

  let joinedString = copiedArray.shift();
  for(let i = 0; i < copiedArray.length; i++) {
    joinedString += separator + copiedArray[i];
  }

  return joinedString;
}

console.log( join(['a', 'b', 'c'], '---') );
// => 'a~b~c'
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?