Created
March 26, 2017 12:39
-
-
Save burakcan/aa40b3f58593a8c08600d43a2caf90f0 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/dipawo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function solution(A) { | |
let num = 0; | |
for (let i = 0; i < A.length; i++) { | |
num += A[i] * Math.pow(-2, i); | |
} | |
let target = -num; | |
let seq = []; | |
const mask = 0xAAAAAAAA; | |
return ( | |
((-num + mask) ^ mask) | |
.toString(2) | |
.split('') | |
.reverse() | |
.map(i => parseInt(i)) | |
); | |
} | |
console.log( | |
solution([1, 0, 0, 1, 1] ) | |
); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function solution(A) { | |
let num = 0; | |
for (let i = 0; i < A.length; i++) { | |
num += A[i] * Math.pow(-2, i); | |
} | |
let target = -num; | |
let seq = []; | |
const mask = 0xAAAAAAAA; | |
return ( | |
((-num + mask) ^ mask) | |
.toString(2) | |
.split('') | |
.reverse() | |
.map(i => parseInt(i)) | |
); | |
} | |
console.log( | |
solution([1, 0, 0, 1, 1] ) | |
);</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(A) { | |
let num = 0; | |
for (let i = 0; i < A.length; i++) { | |
num += A[i] * Math.pow(-2, i); | |
} | |
let target = -num; | |
let seq = []; | |
const mask = 0xAAAAAAAA; | |
return ( | |
((-num + mask) ^ mask) | |
.toString(2) | |
.split('') | |
.reverse() | |
.map(i => parseInt(i)) | |
); | |
} | |
console.log( | |
solution([1, 0, 0, 1, 1] ) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment