MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / bitwiseOp

Function bitwiseOp

chapter08/8.12 - Eight Queens/nQueens.js:19–32  ·  view source on GitHub ↗
(binaryString, n, callback)

Source from the content-addressed store, hash-verified

17};
18
19var bitwiseOp = function(binaryString, n, callback) {
20 var base10 = parseInt(binaryString, 2);
21 base10 = callback(base10);
22 var base2 = base10.toString(2);
23 if (base2.length <= n) {
24 var front = '';
25 for (var i = base2.length; i < n; i++) {
26 front += '0';
27 }
28 return front + base2;
29 } else {
30 return base2.slice(base2.length - n);
31 }
32};
33
34var leftShift = function(binaryString, n) {
35 return bitwiseOp(binaryString, n, (number) => number << 1);

Callers 2

leftShiftFunction · 0.85
rightShiftFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected