Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sum of digits with reduce function

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)))
 
PREVIOUS NEXT
Tagged: #sum #digits #reduce #function
ADD COMMENT
Topic
Name
6+8 =