Skip to content

Latest commit

 

History

History
16 lines (11 loc) · 262 Bytes

head-tail.md

File metadata and controls

16 lines (11 loc) · 262 Bytes

Head tail

def my_reduce(array)
    head, *tail = array
    return (tail.empty? ? head : (head + my_reduce(tail)))
end

# triangular number example
n = 100
my_reduce((1..n).to_a) == (n*(n+1))/2 #=> True

View Source