솔루션
const solution = (bin1, bin2) => {
const answer = (parseInt(bin1, 2) + parseInt(bin2, 2)).toString(2);
console.log(answer);
return answer;
};
솔루션
const solution = (bin1, bin2) => {
let temp = Number(bin1) + Number(bin2);
temp = [...temp.toString()].reverse().map((v) => +v);
for (let i = temp.length; i < 11; i++) {
temp.push(0);
}
for (let i = 0; i < temp.length; i++) {
if (temp[i] === 2) {
temp[i] = 0;
temp[i + 1]++;
} else if (temp[i] === 3) {
temp[i] = 1;
temp[i + 1]++;
}
}
console.log(temp);
const answer = Number(temp.reverse().join("")).toString();
console.log(answer);
return answer;
};
이진수를 코드로 구현할 수 있는지 묻는 문제인지 아니면 레벨0이라서 단순하게 접근해야하는건지 출제자의 의도를 알 수는 없지만,
우리는 개발자이기에 다 할 줄 알아야 한다.
고로 반복 반복
'프로그래머스(Javascript) > Level 0' 카테고리의 다른 글
[프로그래머스 | 자바스크립트] 치킨 쿠폰 (0) | 2023.02.27 |
---|---|
[프로그래머스 | 자바스크립트] 특이한 정렬 (0) | 2023.02.26 |
[프로그래머스 | 자바스크립트] A로 B만들기 (0) | 2023.02.25 |
[프로그래머스 | 자바스크립트] k의 개수 (0) | 2023.02.24 |
[프로그래머스 | 자바스크립트] 중복된 문자 제거 (0) | 2023.02.23 |