코딩테스트

코딩테스트 연습 > 연습문제 > 정수 제곱근 판별

안양사람 2020. 7. 10. 21:37
728x90
SMALL

코드

function solution(n) {
    if(Number.isInteger(Math.sqrt(n))){
        return Math.pow(Math.sqrt(n)+1,2);
    }else{
        return -1;
    }
}

isInteger : 정수를 확인하는 함수

sqrt : 루트

pow 제곱근함수  앞에인자는 밑 뒤에인자는 지수

728x90
LIST