add second parameter to Ox.count

This commit is contained in:
rolux 2012-05-31 00:48:55 +02:00
parent 54266bd3b2
commit 684c4ceaf2

View file

@ -68,13 +68,17 @@ Ox.count <f> Counts the occurences of values in a collection
{f: 1, o: 2} {f: 1, o: 2}
> Ox.count('foo') > Ox.count('foo')
{f: 1, o: 2} {f: 1, o: 2}
> Ox.count('foo', 'f')
1
> Ox.count('foo', 'x')
0
@*/ @*/
Ox.count = function(collection) { Ox.count = function(collection, value) {
var ret = {}; var count = {};
Ox.forEach(collection, function(value) { 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;
}; };
/*@ /*@