<문제설명>
임의의 양의 정수 n에 대해, n이 어떤 양의 정수x의 제곱인지아닌지 판단하려함
n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴
n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함수
function solution(n) {
if (n === Math.sqrt(x)) {
return Math.pow((x+1), 2)
}
return -1
}
<다른 사람의 풀이>
function solution(n) {
let sqrt = Math.sqrt(n);
return Number.isInteger(sqrt) ? Math.pow(sqrt + 1, 2) : -1;
}