These are chat archives for camperbot/bonfire-binary-agents

1st
Nov 2015
Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
bf mutations
CamperBot
@camperbot
Nov 01 2015 09:11

:fire:Bonfire: Mutations :link:

function mutation(arr) {
  return arr;
}

mutation(['hello', 'hey']);

Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

more info:  bf details | bf links | hint

Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
hint
CamperBot
@camperbot
Nov 01 2015 09:11

hint [1/7]

## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
hint
CamperBot
@camperbot
Nov 01 2015 09:11

hint [2/7]

Explanation:

This problem is very straight forward, you will get string that will represent a sentence in binary code, and you need to translate that into words. There is not direct way to do this so you will have to translate twice.

You should first convert from binary to decimal and from decimal before translating those values into characters

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
hint
CamperBot
@camperbot
Nov 01 2015 09:11

hint [3/7]

Hint: 2

Things are easier when focusing on smaller parts, divide the input to focus on one letter at the time.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
hint
CamperBot
@camperbot
Nov 01 2015 09:11

hint [4/7]

Hint: 3

Make sure that each time you transcode a character from binary to decimal, that you reset whatever variable you used to keep track of the ones. Also do not forget to turn everything back into one string.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
hint
CamperBot
@camperbot
Nov 01 2015 09:11

hint [5/7]

Spoiler Alert!

687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

Solution ahead!

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Ihab Baghdadi
@ijb87
Nov 01 2015 09:11
hint
CamperBot
@camperbot
Nov 01 2015 09:11

hint [6/7]

Code Solution:

function binaryAgent(str) {
  biString = str.split(' ');
  uniString = [];

/*using the radix (or base) parameter in parseInt, we can convert the binary 
  number to a decimal number while simultaneously converting to a char*/

   for(i=0;i < biString.length;i++){
   uniString.push(String.fromCharCode(parseInt(biString[i], 2))); 
  }
//we then simply join the string
  return uniString.join('');
}

Code Explanation:

  • Separate the string into an array of strings separated by whitespace.
  • Create some variables that will be needed along the way, the names are self explanatory for the most part.
  • Iterate through each binary string in the new array.
  • Convert to decimal by using parseInt(binary, 2) (with the second parameter we tell in which base our numbers currently are)
  • At the end, we return out converted message.

type hint for next hint :pencil: [Contribute at the FCC Wiki]