I am trying to convert string to number but I am unable to do that , after passing each number from foreach
function sum(num){ num.toString().split('').forEach(add); } function add(value , key) { console.log(value); // 2,3 Number(value); console.log(typeof(value)) // string string } sum(23); In the code - >
After I did Number(value); in function add(value, key) I am still getting string console.log(typeof(value)) // string
var n = Number(value); console.log(typeof(n));const crossSum = num => String(num).split("").reduce((a,b) => a+Number(b), 0);