MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / addBinary

Function addBinary

math/67-add-binary.js:6–11  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

4 * @return {string}
5 */
6var addBinary = function (a, b) {
7 // we used BigInt() to convert binary to Integer. Syntax is BigInt(0b11) here `0b` is prefix and `11` is binary number
8 let sum = BigInt(`0b${a}`) + BigInt(`0b${b}`);
9 // sum is converted back to string using toString(2), here 2 is radix argument, so toString(2) converts to binary
10 return sum.toString(2);
11};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected