Add a test demonstrating folding order

This commit is contained in:
Luchs
2015-01-16 09:48:59 +01:00
parent 4bc06a3acc
commit 82740d2668

View File

@ -1,4 +1,5 @@
var a = [1, 4, 2, 1, 5]
var b = ["W", "o", "r", "l", "d"]
var max = new Fn {|a, b| a > b ? a : b }
var sum = new Fn {|a, b| a + b }
@ -7,3 +8,7 @@ IO.print(a.reduce(10, max)) // expect: 10
IO.print(a.reduce(sum)) // expect: 13
IO.print(a.reduce(-1, sum)) // expect: 12
// sum also concatenates strings
IO.print(b.reduce("Hello ", sum)) // expect: Hello World
IO.print(b.reduce(sum)) // expect: World