function solution(s) {
// 공백으로 구분된 숫자, 최대와 최소를 찾자
const newS = s.split(' ').map((str) => Number(str));
return `${Math.min(...newS)} ${Math.max(...newS)}`;
}
'test'.split('') -> ['t','e','s','t']
'test'.split('').join('') -> 'test'
Math.max, Math.min -> parameter 개수 제한 없음
function solution(s) {
const toBinary = (num) => {
const binary = [];
while(num > 1) {
binary.push(num % 2);
num = parseInt(num / 2);
}
binary.push(1);
return binary.reverse().join('');
}
const toOne = (str, step, deleteZeroCount) => {
if(str === '1')
return [step, deleteZeroCount];
const zeroCount = str.split('').filter((c) => Number(c) === 0).length
return toOne(toBinary(str.split('').length - zeroCount), step+1, deleteZeroCount + zeroCount)
}
return toOne(s, 0, 0);
}