Skip to content

Instantly share code, notes, and snippets.

@ronaldoarg
Created April 5, 2018 18:21
Show Gist options
  • Save ronaldoarg/b82ac124610bf9359fb1fc1fa07a6c52 to your computer and use it in GitHub Desktop.
Save ronaldoarg/b82ac124610bf9359fb1fc1fa07a6c52 to your computer and use it in GitHub Desktop.
My solution for FreeCodeCamp for Binary Agents challenge.
function binaryAgent(str) {
return String.fromCharCode.apply(this, str.split(' ').map(binaryToString));
}
function binaryToString(binary) {
return binary.split('').reverse().reduce(function(acc, item, index) {
return acc + Math.pow(2, index) * item;
}, 0);
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment