[프로그래머스 | 자바스크립트] 다음에 올 숫자
프로그래머스(Javascript)/Level 0
2023. 2. 4. 14:14
솔루션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; };