I wanted to create a function which take a string of any numbers and characters as a one parameter. the task is to find all the even numbers(digits) and sum them up then display the total value in console. for example, if the following string is passed to this function as a one parameter ("112,sf34,4)-k)") the result should be : The sum of all even numbers: 10
So far I have come with solution and solve after this. Help me. Thanks in advance.
function functionFive(str) {
const string = [...str].map(char => {
const numberString = char.match(/^\d+$/)
if (numberString !== null){
const number = parseInt(numberString)
return number
}
const num = string.map(number=>{
if (number !== undefined && number%2 === 0){
console.log(number)
}
})
}
functionFive("sau213e89q8e7ey1")