mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Add a test demonstrating folding order
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user