1. 0~9 까지 숫자 배열 생성
Array.from({length:10}, (val,idx)=>idx)
2. 정수 난수 생성 min<=n<max 인 난수 생성
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //최댓값은 제외, 최솟값은 포함
}
[출처] https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/random
3. for~of index 값 얻기
for (const [i, v] of ['a', 'b', 'c'].entries()) {
console.log(i, v)
}
4. 백준 input
https://mingcoder.me/2020/01/15/Programming/etc/acmicpc-nodejs-input/
5. 다차원배열
const arr2 = Array.from(Array(5), () => Array(2).fill(0)) // 0으로 초기화
'dev > JavaScript' 카테고리의 다른 글
debounce와 throttle (0) | 2020.08.20 |
---|---|
JavaScript 안정 정렬 (2) | 2020.07.28 |
CPS 예외 처리 패턴 (1) | 2019.11.18 |
자바스크립트 Execution Context 1 (0) | 2019.06.24 |
화살표 함수와 this (0) | 2019.05.30 |