add second parameter to Ox.count
This commit is contained in:
parent
54266bd3b2
commit
684c4ceaf2
1 changed files with 8 additions and 4 deletions
|
@ -68,13 +68,17 @@ Ox.count <f> 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;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
Loading…
Reference in a new issue