function NumberSearch(str) {
var arr = str.split("");
var sum = 0;
var twoDigit = [];
var two;
var res = [];
var arrFormat = preProcess(arr);
console.log(arrFormat);
//this custom function obtains an array containing all numbers from the string
function preProcess(ele) {
for (var i = 0; i < ele.length; i++) {
if (typeof ele[i] === 'number' && typeof ele[i + 1] === 'number') {
twoDigit.push(ele[i], ele[i + 1]);
two = twoDigit.join("");
res.push(two);
} else {
if (typeof ele[i] === 'number' && typeof ele[i + 1] !==
'number') {
res.push(ele[i]);
}
}
}
return res;
}
for (var k = 0; k < arrFormat.length; k++) {
sum = sum + arrFormat[k];
}
return sum;
}
console.log(NumberSearch("99Hello1"));
The approach I'm taking involves iterating through the string to gather all numeric values and then calculating their total.