Skip to content
Browse files

simple reduce impl

  • Loading branch information...
1 parent 03cf515 commit be04efa05c42797c33a126501c52d79adf43acf3 @krukow krukow committed Oct 27, 2011
Showing with 9 additions and 0 deletions.
  1. +9 −0 utils/utils.dart
View
9 utils/utils.dart
@@ -41,3 +41,12 @@ map_with_index(coll, f [context]) {
map(coll, f) {
return map_with_index(coll, (x,_,__)=>f(x));
}
+
+reduce(coll, init, f) {
+ if (coll.length == 0) return init;
+ var cur = init;
+ coll.forEach((v) {
+ cur = f(cur,v);
+ });
+ return cur;
+}

0 comments on commit be04efa

Please sign in to comment.
Something went wrong with that request. Please try again.