Skip to content

Instantly share code, notes, and snippets.

@JeffOgah
Last active February 23, 2019 07:14
Show Gist options
  • Select an option

  • Save JeffOgah/98b841e9fca87419a150865e3636476c to your computer and use it in GitHub Desktop.

Select an option

Save JeffOgah/98b841e9fca87419a150865e3636476c to your computer and use it in GitHub Desktop.
JavaScript Intermediate Algorithm Scripting: Binary Agents
// Return an English translated sentence of the passed binary string. The binary string will be space separated.
function binaryAgent(str) {
//split str separated by space then map each binary string to dec
let arr = str.split(" ").map(item => parseInt(item, 2));
//map each dec to string equivalent and join characters
return arr.map(item => String.fromCharCode(item)).join("");
}
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