https://programmers.co.kr/learn/courses/30/lessons/12932
function solution(n) {
var answer = [];
while(n > 0){
answer.push(n%10);
n = parseInt(n / 10); // parseInt or Math.floor을 써서 소수점 없애기
}
return answer;
}
parseInt와 Math.floor 차이
f1 = Math.floor( "-1.2" ); // -2
f2 = Math.floor( "-3.4" ); // -4
p1 = parseInt( "-1.2" ); // -1
p2 = parseInt( "-3.4" ); // -3
양수일 때는 결과값이 같지만 음수일 때는 다르다.
parseInt는 올림을 하여 -1가 나오며
Math.floor는 내림을 하기 때문에 -2가 나온다.
속도 측면에서는 Math.floor가 조금 더 빠르다고 한다.