Doubt Solving

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”

Won’t this program, with the given example, read the four numbers 3,1,1,0 instead of the number 3110?

No, it won’t work

The program you provided has limitations as it only considers consecutive digits as separate numbers. To solve the problem correctly, you can use regular expressions to extract individual numbers from the given sentence. Then, parse the extracted numbers as integers and calculate their sum. Finally, print the sum to the console.

You can refer to resources such as MDN Web Docs for regular expressions, JavaScript String methods, and online learning platforms like Codecademy and FreeCodeCamp to deepen your understanding of the concepts and improve your problem-solving skills.