Skip to content

Instantly share code, notes, and snippets.

@Sposito
Last active June 2, 2016 03:02
Show Gist options
  • Save Sposito/acddd2f6f826c69205f85a2096bca729 to your computer and use it in GitHub Desktop.
Save Sposito/acddd2f6f826c69205f85a2096bca729 to your computer and use it in GitHub Desktop.
//FreeCodeCamp solution by Thiago Sposito
/// ###################### STEAMROLER #####################################
function steamrollArray(arr) {
// I'm a steamroller, baby
var result = [];
recursiveDigger(arr);
return result;
function recursiveDigger(array) {
if (Array.isArray(array)) {
for (var i = 0; i < arr.length; i++) {
recursiveDigger(array[i]);
}
}
else if(array != undefined) {
result.push(array);
console.log(result);
}
}
}
steamrollArray([1, [2], [3, [[4]]]]);
/// ###################### Binary Agent #####################################
function binaryAgent(str) {
codes = str.split(' ');
test = "";
for (var i = 0; i < codes.length; i++){
codes[i] = String.fromCharCode(DecimalNumberFromBinary(codes[i]));
test += codes[i];
}
return test;
}
function DecimalNumberFromBinary(binaryStr){
var result = 0;
var reverse = binaryStr.split("").reverse().join("");
for (var i = 0; i < reverse.length; i++){
if(reverse[i] == 1){
result += Math.pow(2, i);
}
}
return result;
}
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