common의 마지막 원소와 그 직전원소의 차이, 직전원소와 그것의 직전원소의 차이를 비교해 같다면 등차수열이다
👉 다음에 올 숫자는 차이값을 마지막 원소에 더해준 것
차이가 있다면 등비수열
👉 마지막원소를 직전원소로 나눈 값(공비)을 마지막 원소에 곱해주면 된다
function solution(common) {
var answer = 0;
for (let i=0; i<common.length; i++){
if(common[common.length-1]-common[common.length-2] == common[common.length-2]-common[common.length-3]){
answer = common[common.length-1]+common[common.length-1]-common[common.length-2]
}else{
answer = common[common.length-1]*common[common.length-1]/common[common.length-2]
}
}
return answer;
}
이 문제는 등비수열과 등차수열의 규칙을 잘 알고 있으면 쉽게 풀 수 있었던 문제였던 것 같다