Add reduce function on Sequence

This commit is contained in:
Luchs
2015-01-16 09:24:59 +01:00
parent 64c2bd7633
commit 4c6b819ed1
5 changed files with 31 additions and 0 deletions
+9
View File
@@ -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