Hi guys. I know it’s probably not the best code ever. But I’d like to hear your opinion on how to make it clearer.
function binaryAgent(str) {
let arrOfBin=str.split(' ');
let arrOfDec=[];
function toDecimal(num,arrayToPush){
let arr=num.split("");
let degree=num.length-1;
let result=0;
for (let i=0;i<arr.length;i++){
result+=arr[i]*Math.pow(2,degree);
degree--;
}
arrayToPush.push(result);
}
for (let bin of arrOfBin){
toDecimal(bin,arrOfDec);
}
return String.fromCharCode(...arrOfDec);
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");