본문 바로가기
Coding Test/JavaScript

[Javascript] (백준 2729) 이진수 덧셈

by Chaedie 2022. 6. 25.
728x90

💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다.

내 풀이

//* 인풋 - 디폴트
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = require('fs').readFileSync(filePath).toString().split('\\n');

//* 인풋 - 커스텀, 함수 콜
const n = +input[0];

for (let i = 0; i < n; i++) {
  const [a, b] = input[i + 1].split(' ');
  const answer = solution(a, b);
  console.log(answer.trim());
}

//* 로직함수
function solution(a, b) {
  return (BigInt(`0b${a}`) + BigInt(`0b${b}`)).toString(2);
}

배운 점, 느낀 점

미쳤다 미쳤다 미쳤다 미쳤다 미쳤다 미쳤다 미쳤다 미쳤다

자바스크립트는 진짜 갓 언어다.

자바스크립트 미쳤다리 쿵쿵따

BigInt로 해결이 안되서 좀 찾아보니 BigInt(`0b${a}1) 로 해결이 되네요 미쳤다리 미쳤다 미쳤다리 미쳤다

댓글