here is the code I have for Binary agents
function binaryAgent(str) {
var charNum = [125,64,32,16,8,4,2,1];
var splitString = str.split(""); //splits the str param
var mult = 0; //will bes used to index charNum
var resultofChar = []; // holds the 8 digits after they multiply
var x = []; // holds the number returned after reduce
var finalAns;//holds the letter returned
for(var i = 0; i<splitString.length; i++){
if(mult === 8){
mult = 0;
}
var char = Number(splitString[i]) * charNum[mult];//mutlplies splitstring whit values in charnum
resultofChar.push(char); // pushes that char to the array resultofChar
mult++; //increases mult by on so it can me mult by the next number in charNum
if(mult === 8){
x = resultofChar.reduce(function (acc ,curr){
return acc + curr;
},0);
}
finalAns= String.fromCharCode(x); // holds the letter A
//As it stands now it only applies to first 8 digits.
}
return finalAns;
}
binaryAgent("01000001");
It does work for the parameter passed in. However if more string are passed in it falls apart. What can I change to make it work on multiple binary agents.?
here is the link to the challenge
https://www.freecodecamp.org/challenges/binary-agents