Add reduce function on Sequence
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
var a = [1, 4, 2, 1, 5]
|
||||
var max = new Fn {|a, b| a > b ? a : b }
|
||||
var sum = new Fn {|a, b| a + b }
|
||||
|
||||
IO.print(a.reduce(max)) // expect: 5
|
||||
IO.print(a.reduce(10, max)) // expect: 10
|
||||
|
||||
IO.print(a.reduce(sum)) // expect: 13
|
||||
IO.print(a.reduce(-1, sum)) // expect: 12
|
||||
@@ -0,0 +1 @@
|
||||
[1].reduce {|a, b| a } // expect runtime error: Range start out of bounds.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].reduce {|x, y, z| x } // expect runtime error: Function expects more arguments.
|
||||
Reference in New Issue
Block a user