From 684c4ceaf22d98b733643878dd447431915dd36d Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 31 May 2012 00:48:55 +0200 Subject: [PATCH] add second parameter to Ox.count --- source/Ox/js/Collection.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/Ox/js/Collection.js b/source/Ox/js/Collection.js index ffad45c9..e8943035 100644 --- a/source/Ox/js/Collection.js +++ b/source/Ox/js/Collection.js @@ -68,13 +68,17 @@ Ox.count Counts the occurences of values in a collection {f: 1, o: 2} > Ox.count('foo') {f: 1, o: 2} + > Ox.count('foo', 'f') + 1 + > Ox.count('foo', 'x') + 0 @*/ -Ox.count = function(collection) { - var ret = {}; +Ox.count = function(collection, value) { + var count = {}; Ox.forEach(collection, function(value) { - ret[value] = (ret[value] || 0) + 1; + count[value] = (count[value] || 0) + 1; }); - return ret; + return value ? count[value] || 0 : count; }; /*@