// 문제 : 정수 num1, num2가 매개변수로 주어질 때, num1을 num2로 나눈 몫을 return 하도록 solution 함수를 완성해주세요.
// 반성 : Math.floor()와 parseInt()만 알고있었는데 다른 방법들을 보고 너무 놀랐음.
double tilde(~~)와
<< shift연산자
function solution(num1, num2) {
return parseInt(num1 / num2);
}
function solution(num1, num2) {
var answer = num1 / num2;
return Math.floor(answer);
}
function solution(num1, num2) {
return (num1 / num2) << 0;
}
function solution(num1, num2) {
return Math.trunc(num1 / num2);
}
function solution(num1, num2) {
return ~~(num1 / num2);
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift
'Algorithm' 카테고리의 다른 글
[JavaScript] 프로그래머스 - 나이 출력 (0) | 2023.01.01 |
---|---|
[JavaScript] 프로그래머스 - 두 수의 나눗셈 (0) | 2022.10.22 |
[JavaScript] 프로그래머스 - 직사각형 별찍기 (0) | 2022.09.27 |
[JavaScript] 프로그래머스 - 부족한 금액 계산하기 (1) | 2022.09.25 |
[JavaScript] 문자열 내림차순으로 배치 (1) | 2022.09.25 |