0
1

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文法総復習

Last updated at Posted at 2020-05-19

#目的
HackerRankをやりながら忘れそうな文法を記載していきます。

##配列の合計値の計算
配列の中身を一つ一つ処理して合計を計算する。
####昔風

sample.js
const array=[1,2,3,4,5];
let sum=0;

for(let i; i<array.length: i++){
 sum+=array[i];
}

####ちょっと今風

sample.js
array.forEach((num) => {sum+=num})

####そのほか

sample.js
let sum = array.reduce((a, c) => {return a + c})

##文字列の繰り返し
ES6ではrpeat()が使える

sample.js
string='A'.repeat(3);
console.log(string);
// AAA

##文字列の分割

sample.js
str="ABCDE";
str.slice(1,3);
//BC

##string to int, int to string

sample.js
parseInt(string);
String(int);

##JavaScriptにリストは無い
配列をリストのように扱うことができる

sample.js
array.push()

forEachとmapとfilterの違い

https://qiita.com/Uuparu/items/e9867cb6c48736700a4f

とてつもなくでかい数字の比較

BigInt(a)>BigInt(b)
0
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?