Add reduce function on Sequence
This commit is contained in:
@@ -21,6 +21,16 @@ class Sequence {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
reduce(acc, f) {
|
||||
for (element in this) {
|
||||
acc = f.call(acc, element)
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
reduce(f) { this[1..-1].reduce(this[0], f) }
|
||||
|
||||
}
|
||||
|
||||
class List is Sequence {
|
||||
|
||||
Reference in New Issue
Block a user