Algorithm/스킬
-
배열 채우기Algorithm/스킬 2021. 3. 11. 23:24
1. n의 크기를 가진 배열에 특정 데이터 1가지로 모두 채우기 (0으로 채우기) 1.1 fill() new Array(n).fill(0); 1.2 from() Array.from({ length: n }, () => 0); 2. 크기가 n인 배열에 오름차순 데이터로 채우기 2.1 0부터 n까지 오름차순으로 채우기 [...new Array(n).keys()] 2.2 특정 값 a부터 n개의 데이터를 오름차순으로 채우기 [...new Array(n).keys()].map(el => el + a) Array.from({ length: n }, (v, i) => i + a)