[프로그래머스 | 자바스크립트] 연속된 수의 합
프로그래머스(Javascript)/Level 0
2023. 2. 4. 15:55
솔루션1 const solution = (num, total) => { const numArray = Array.from({ length: num }, (_, i) => i); const sum = numArray.reduce((x, y) => x + y); const answer = numArray.map((v) => v - (sum - total) / num); console.log(answer); return answer; }; 솔루션2 const solution2 = (num, total) => { let answer = []; let ceilNum = Math.ceil(total / num - Math.floor(num / 2)); console.log(ceilNum); answer = Arra..