사랑하애오
[프로그래머스 | 자바스크립트] 연속된 수의 합

솔루션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..

[프로그래머스 | 자바스크립트] 다음에 올 숫자

솔루션1 const solution = (common) => { const isTrue = (arr) => arr[2] - arr[1] === arr[1] - arr[0]; // 배열의 2번째 1번째 뺀 값이 1번째 0번째 뺀 값이랑 같니 console.log(isTrue(common)); // true, false const answer = isTrue(common) ? common[common.length - 1] + common[1] - common[0] // true면 등차수열 : common[common.length - 1] * (common[1] / common[0]); // false면 등비수열 console.log(answer); return answer; };

[프로그래머스 | 자바스크립트] 옹알이

솔루션1 const convertPWordsToNum = (word) => { const pWords = ["aya", "ye", "woo", "ma"]; return pWords.reduce((result, pWord, i) => result.replaceAll(pWord, i), word); }; const canPronounce = (word) => { const result = convertPWordsToNum(word); return ( !/[^\d]/.test(result) && [...result].every( (num, i) => i + 1 > result.length || num !== result[i + 1] ) ); }; function solution(babbling) { conso..