[Lv.1] 정수 제곱근 판별*

01수정·2023년 11월 2일
0

문제


풀이

  • Math.sqrt
  • Number.isInteger
function solution(n) {
    let sqrt = Math.sqrt(n);
    if (Number.isInteger(sqrt)) {
        return (sqrt+1) * (sqrt+1)
    } else { 
        return -1
    }
}

다른 풀이

  • Math.pow
function solution(n) {
   return Number.isInteger(Math.sqrt(n)) ? Math.pow(Math.sqrt(n) + 1,2) : -1
}
profile
새싹 FE 개발자

0개의 댓글