sum of number using reduce sum of digits with reduce function

The solution for “sum of number using reduce sum of digits with reduce function” can be found here. The following code will assist you in solving the problem.

console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)import functools
from functools import reduce

def sum_of_digits(number):
return functools.reduce(add, to_list(number))

def add(x, y):
return x + y

def to_list(num):
return list(map(int, str(num)))

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in