Skip to content

Instantly share code, notes, and snippets.

@ineersa
Created February 8, 2022 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ineersa/cdb296b98671adcadd4a7249096dd847 to your computer and use it in GitHub Desktop.
Save ineersa/cdb296b98671adcadd4a7249096dd847 to your computer and use it in GitHub Desktop.
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