(Javascript) Write a function that accepts an array. The function adds its value with the value of the character before to it to generate a number. It returns a string of numbers.
function subtracts(lst){ result = ""; var k1, k2; for(var i = 0;i<lst.length-1;i++){ if(typeof lst[i] == "string"){ k1 = lst[i].charCodeAt(); } else{ k1 = lst[i]; } if(typeof lst[i+1] == "string"){ k2 = lst[i+1].charCodeAt(); } else{ k2 = lst[i+1]; } ch = String.fromCharCode(Math.abs(k1+k2)); if(i == 0){ result = result + ch; } else{ result = result + ","+ ch; } } return result; }
Get Answers For Free
Most questions answered within 1 hours.