Created
July 16, 2019 15:29
-
-
Save elisavetTriant/b7299c7e8a252a5f1baffbf48de7371b 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
/* | |
Intermediate Algorithm Scripting: Binary Agents | |
Return an English translated sentence of the passed binary string. | |
The binary string will be space separated. | |
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents | |
More on converting between binary and readable strings on: https://ourcodeworld.com/articles/read/380/how-to-convert-a-binary-string-into-a-readable-string-and-vice-versa-with-javascript*/ | |
function binaryAgent(str) { | |
return str.split(" ").map(function (elem) { | |
return String.fromCharCode(parseInt(elem, 2)); | |
}).join("");; | |
} | |
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"); | |
/*binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111") should return "Aren't bonfires fun!?" | |
Passed | |
binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001") should return "I love FreeCodeCamp!" | |
Passed*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment