Created
February 8, 2022 15:11
-
-
Save ineersa/cdb296b98671adcadd4a7249096dd847 to your computer and use it in GitHub Desktop.
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
var input = [ | |
'00100', | |
'11100', | |
'11000', | |
'11011', | |
'11011', | |
]; | |
let gamma = ''; | |
for (let i=0; i<input[0].length; i++) { | |
let counter = 0; | |
for (let binary of input) { | |
if (+binary[i] === 1) { | |
counter += 1; | |
} | |
} | |
if (counter > (input[0].length / 2)) { | |
gamma += '1'; | |
} else { | |
gamma += '0'; | |
} | |
} | |
console.log(gamma); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment