Unexpected result from reduce function
Posted
by StackedCrooked
on Stack Overflow
See other posts from Stack Overflow
or by StackedCrooked
Published on 2010-05-11T22:40:52Z
Indexed on
2010/05/11
22:44 UTC
Read the original article
Hit count: 188
clojure
I would like to get the smallest element from a vector. For this I use combine the reduce
and min
functions. However, when providing my own implementation of min
I get unexpected results:
user=> (reduce (fn [x y] (< x y) x y) [1 2 3 2 1 0 1 2])
2
user=> (reduce min [1 2 3 2 1 0 1 2 3])
0
The reduce with standard min
returns 0 as expected. However, when I provide my own implementation it returns 2. What am I doing wrong?
© Stack Overflow or respective owner