https://programmers.co.kr/learn/courses/30/lessons/12932
function solution(n) {
var answer = [];
var str= n.toString();
var arr = str.split('');
var newArr = arr.reverse();
answer = newArr.map(str => parseInt(str,10));
console.log(answer);
return answer;
}
처음에 왜 틀렸지? => '뒤집어'(역순) 배열로 만들어야 하는데, 그냥 내림차순 sort함.
reverse method없이 for문으로 풀어보기 - index 이용해보기
2. 2019
function solution(n) {
var answer = [];
var filppedString = '';
var numberToString = n.toString();
var lengthOfNumber = numberToString.length;
//flip over
for ( var i=0; i<lengthOfNumber; i++ ){
filppedString = filppedString + numberToString[(lengthOfNumber- 1) - i];
}
// put into array
for( var j=0; j<lengthOfNumber; j++){
answer[j] = parseInt(filppedString[j]);
}
return answer;
}