add Ox.numberOf: sugar for Ox.len(Ox.filter(collection, test))
This commit is contained in:
parent
4b01e4984b
commit
c99316916c
1 changed files with 19 additions and 0 deletions
|
@ -343,6 +343,25 @@ Ox.min = function(collection) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.numberOf <f> Returns the number of elements in a collection that pass a test
|
||||
(collection, test) -> <n> Number of elements
|
||||
collection <a|o|s> Collection
|
||||
test <f> Test function
|
||||
value <*> Value
|
||||
key <n|s> Key
|
||||
collection <a|o|s> Collection
|
||||
> Ox.numberOf([0, 1, 0, 1], function(v) { return v; })
|
||||
2
|
||||
> Ox.numberOf({a: 'a', b: 'c'}, function(v, k) { return v == k; })
|
||||
1
|
||||
> Ox.numberOf('foo', function(v, k, c) { return v == c[k - 1]; })
|
||||
1
|
||||
@*/
|
||||
Ox.numberOf = function(collection, test) {
|
||||
return Ox.len(Ox.filter(collection, test));
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.remove <f> Removes an element from an array or object and returns it
|
||||
(collection, element) -> <*> Element, or undefined if not found
|
||||
|
|
Loading…
Reference in a new issue