Why my program is not working for all tests of this question ?
const sentence = readline();
var arr = new Array();
for(let i = 0;i<sentence.length;i++){
var c = sentence.charCodeAt(i);
if(c>=48 && c<=57){
arr.push(sentence[i]);
}
}
var sum =0;
for(let j=0;j<arr.length;j++){
sum+=Number(arr[j]);
}
console.log(sum);
You are given a string sentence as input, you must find the different numbers contained in this variable and display their sum.
For instance, if sentence is “h3110 w0r1d !”, you can find “3110”, “0” and “1” in it. You have to print their sum: “3111”