Ad

Ok now if you enter binary it will convert the 'whoever' name into binary string
Am i going too far ?

Code
Diff
  • var numberToBinaryArray = (number) => {
    	var result = [];
    	while(number > 0){
    		var bit = Math.floor(number % 2) != 0 ? 1 : 0;
    		result.unshift(bit)
    		number = Math.floor(number / 2);
    	}
    	while(result.length != 8)
    		result.unshift(0);
    	return result;
    }
    
    var txtToBin = (text) => {
    	var result = [];
    	for(var i = 0; i < text.length; i++){
    		var binaryArr = numberToBinaryArray(text.charCodeAt(i));
    		result = result.concat(binaryArr);
    	}
    	return result.join("");
    }
    
    let helloLangs = {
      english: "hello",
      pirate: "yar",
      binary: txtToBin('hello')
    }
    
    const hello = (whoever, lang="english") => `${helloLangs[lang]} ${lang == 'binary' ? txtToBin(whoever) : whoever}`;
    • var numberToBinaryArray = (number) => {
    • var result = [];
    • while(number > 0){
    • var bit = Math.floor(number % 2) != 0 ? 1 : 0;
    • result.unshift(bit)
    • number = Math.floor(number / 2);
    • }
    • while(result.length != 8)
    • result.unshift(0);
    • return result;
    • }
    • var txtToBin = (text) => {
    • var result = [];
    • for(var i = 0; i < text.length; i++){
    • var binaryArr = numberToBinaryArray(text.charCodeAt(i));
    • result = result.concat(binaryArr);
    • }
    • return result.join("");
    • }
    • let helloLangs = {
    • english: "hello",
    • pirate: "yar"
    • pirate: "yar",
    • binary: txtToBin('hello')
    • }
    • const hello = (whoever, lang="english") => `${helloLangs[lang]} ${whoever}`;
    • const hello = (whoever, lang="english") => `${helloLangs[lang]} ${lang == 'binary' ? txtToBin(whoever) : whoever}`;