There was an error while loading. Please reload this page.
2 parents 153145a + 3bc46ea commit 554bcd4Copy full SHA for 554bcd4
.vscode/settings.json
@@ -1,3 +1,5 @@
1
{
2
- "cSpell.words": ["MCMXCIV", "Palindrom", "strs"]
+ "editor.fontSize": 16,
3
+ "editor.fontLigatures": false,
4
+ "editor.fontWeight": "normal"
5
}
67-addBinary.js
@@ -0,0 +1,20 @@
+const addBinary = (a, b) => {
+ let sum = '',
+ carry = 0;
+
+ a = a.split('');
6
+ b = b.split('');
7
+ const len = Math.max(a.length, b.length);
8
+ for (let i = 0; i < len; i++) {
9
+ const x = parseInt(a.pop() || 0);
10
+ const y = parseInt(b.pop() || 0);
11
+ const temp = x + y + carry;
12
+ sum = (temp % 2) + sum;
13
+ carry = Math.floor(temp / 2);
14
+ }
15
+ if (carry) sum = carry + sum;
16
17
+ return sum;
18
+};
19
20
+console.log(addBinary('1010', '1011'));
0 commit comments