[프로그래머스] 코딩테스트 연습 - x만큼 간격이 있는 n개의 숫자

김예림·2021년 11월 8일
0

제시된 문제는

function solution(x, n) {
   var answer = [];
    for (let i = 1; i<=n; i++){
        answer.push(x*i);
    }
    return answer;
}

fill 함수를 사용한 다른 사람의 풀이

function solution(x, n) {
return Array(n).fill(x).map((v, i) => (i + 1) * v)
}

profile
초보개발자

0개의 댓글