Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 시즌1
- SQL
- VMware
- JavaScript
- Linux
- 7kyu
- class파일바로보기
- 사용자변경
- Python
- 이것이리눅스다
- 멀티쓰레드프로그래밍
- java
- CentOS
- 오류
- 남산타워뷰
- 8kyu
- Oralce
- 서울에어비앤비
- 자바기초스터디
- 주민번호마스킹
- Codewars
- 6kyu
- 중첩쿼리
- 파이썬
- 서울복층에어비앤비
- 이클립스
- CentOS8
- Eclipse
- monthPicker
- https
Archives
- Today
- Total
보통사람
[7kyu] 해당 정수가 제곱근인지 확인 (You're a square!) 본문
/**
* <pre>
* 해당 정수가 제곱근인지 확인 (You're a square!)
*
* 정수가 주어 졌을 때 그 수가 제곱인지 확인하십시오.
* 수학에서 정사각형 수 또는 완전한 정사각형은 정수의 제곱 인 정수입니다.
* 다시 말해서, 그것은 정수 자체의 결과입니다.
* 테스트에서는 항상 정수를 사용하므로 동적 유형 지정 언어에서는 걱정하지 마십시오.
*
* Given an integral number, determine if it's a square number:
* In mathematics, a square number or perfect square is an integer that is the square of an integer;
* in other words, it is the product of some integer with itself.
* The tests will always use some integral number, so don't worry about that in dynamic typed languages.
*
* </pre>
*
* @auther : pej
* @date : 2019. 03. 16.
* @param : {int} 확일할 정수
* @return : {Boolean} true / false
* @example : isNumber(val);
*
*/
function isSquare (num) {
var root = Math.sqrt(num);
if (root % 1 == 0) {
return true;
} else {
return false;
}
}
-
방법2) - 다른 사람이 한 것
function isSquare (num) {
return Math.sqrt(num) % 1 === 0;
}
-
방법3) - 다른 사람이 한 것
function isSquare (num) {
return Number.isInteger(Math.sqrt(num));
}
'Codewars > Javascript' 카테고리의 다른 글
[7kyu] 정수 내림차순으로 반환 (Descending Order) (0) | 2019.08.02 |
---|---|
[7kyu] 문자열 'x'와'o'의 개수가 같은지 비교 (Exes and Ohs) (0) | 2019.08.02 |
[7kyu] 가장 짧은 단어의 길이 찾기 (Shortest Word) (0) | 2019.08.02 |