Logo

Programming-Idioms

History of Idiom 54 > diff from v49 to v50

Edit summary for version 50 by fridi:
[Clojure] Fixed wrong result

Version 49

2021-04-17, 20:23:49

Version 50

2021-06-06, 08:51:39

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Variables
s,x
Variables
s,x
Code
(defn sum [xs] (reduce + xs))

(sum [1 20 300])
;;=> 123
Code
(defn sum [xs] (reduce + xs))

(sum [1 20 300])
;;=> 321
Comments bubble
xs is a collection of integers.
Comments bubble
xs is a collection of integers.