Algorithm/codewars

You're a square! 답안

Bonita SY 2021. 3. 23. 19:32
728x90
반응형

문제)

www.codewars.com/kata/54c27a33fb7da0db0100040e/train/javascript

 

Codewars: Achieve mastery through challenge

Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

www.codewars.com

 

내가 푼 답)

var isSquare = function(n){
  if (n < 0) {
    return false;
  } else if (n === 0) {
    return true;
  } else {
    var i = 1;
    while((i*i) <= n) {
      if ((i*i) === n) {
        return true;
      }
      i += 1;
    }
    return false;
  }
}

 

테스트 결과)

 

잘 풀었다고 생각되는 다른 사람 소스)

728x90
반응형

'Algorithm > codewars' 카테고리의 다른 글

Is this a triangle? 답안  (0) 2021.03.23
Exes and Ohs 답안  (0) 2021.03.23
Descending Order 답안  (0) 2021.03.23
Convert string to camel case 답안  (0) 2021.03.23
Categorize New Member 답안  (0) 2021.03.23