메서드는 주어진 함수의 테스트를 통과하는 모든 요소를 모아 새로운 배열로 반환합니다.
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']; const result = words.filter(word => word.length > 6); console.log(result); // 길이가 6이상인 문자열로 구성된 배열로 리턴된다.
const val1 = 'my string'; const val2 = 'my string2'; const litVal = `${val1}, ${val2}` console.log(litVal); // my string, my string2
arrs.sort((a,b) =>{ return a[2] - b[2]; });
answer = Math.max(answer, dy[i]);
for (const [t, f, v] of fares) d[t - 1][f - 1] = d[f - 1][t - 1] = v;
const visit = Array.from({length: n+1}, () => 0);
0으로 초기화된 배열
const arr = Array.from(Array(n+1), () => Array(n+1).fill(Infinity));
Infinity 무한으로 초기화
let graph = Array.from(Array(n+1), () => []);
const name = ''
const userName = num || 'undefined';
console.log(userName);
const num = 0;
const message = num ?? 'undefined';
console.log(message);
값이 있는지 없는지 파악해서 변수에 넣어줌
|| 의 경우 '' 값을 null값으로 인식
?? 의 경우 '' 값으로 인식
let total = [1, 2, 3, 4, 5].reduce( ( acc, curr ) => acc + curr, 0 ); console.log(total) // 결과값: 15
let total=arr.reduce((a, b)=>a+b, 0);
let max = [1, 2, 3, 4, 5].reduce( ( max, cur ) => Math.max( max, cur ), -Infinity ); console.log(max) // 결과값: 5