Created
April 5, 2018 18:21
-
-
Save ronaldoarg/b82ac124610bf9359fb1fc1fa07a6c52 to your computer and use it in GitHub Desktop.
My solution for FreeCodeCamp for Binary Agents challenge.
This file contains hidden or 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 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