Skip to content

Instantly share code, notes, and snippets.

@minsooshin
Created November 26, 2015 04:24
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 minsooshin/8684322614adb5845dfb to your computer and use it in GitHub Desktop.
Save minsooshin/8684322614adb5845dfb to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Binary Agents
// Bonfire: Binary Agents
// Author: @minsooshin
// Challenge: http://www.freecodecamp.com/challenges/bonfire-binary-agents
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function binaryAgent(str) {
var arr = str.split(' '),
newStr = '';
arr.forEach(function(val) {
var sum = 0;
for (var i = 0; i < val.length; i++) {
sum += val[i] * Math.pow(2, val.length - 1 - i);
}
newStr += String.fromCharCode(sum);
});
return newStr;
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
//=> Aren't bonfires fun!?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment