Skip to content

Instantly share code, notes, and snippets.

@burakcan
Created March 26, 2017 12:39
Show Gist options
  • Save burakcan/aa40b3f58593a8c08600d43a2caf90f0 to your computer and use it in GitHub Desktop.
Save burakcan/aa40b3f58593a8c08600d43a2caf90f0 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/dipawo
<!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>
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