function for the sum of all even numbers
The below code help you with minimum loops
function sumEven(s) {
return s
.split("")
.filter(x => x % 2 === 0)
.reduce((acc, val) => acc + Number(val), 0);
}
console.log(sumEven("112,sf34,4)-k)"));
Would this help?
function sumEven(s) {
return s.split('').map(x=>+x).filter(x=>x%2==0).reduce((a,b)=>a+b)
}
console.log(sumEven('idsv366f4386523ec64qe35c'))