* @ngdoc filter * @name filter * @kind function * * @description * Selects a subset of items from `array` and returns it as a new array. * * @param {Array} array The source array. * @param {string|Object|function()} expression The predicate to be used for selecting items from * `array`.
()
| 16627 | </example> |
| 16628 | */ |
| 16629 | function filterFilter() { |
| 16630 | return function(array, expression, comparator) { |
| 16631 | if (!isArray(array)) return array; |
| 16632 | |
| 16633 | var predicateFn; |
| 16634 | var matchAgainstAnyProp; |
| 16635 | |
| 16636 | switch (typeof expression) { |
| 16637 | case 'function': |
| 16638 | predicateFn = expression; |
| 16639 | break; |
| 16640 | case 'boolean': |
| 16641 | case 'number': |
| 16642 | case 'string': |
| 16643 | matchAgainstAnyProp = true; |
| 16644 | //jshint -W086 |
| 16645 | case 'object': |
| 16646 | //jshint +W086 |
| 16647 | predicateFn = createPredicateFn(expression, comparator, matchAgainstAnyProp); |
| 16648 | break; |
| 16649 | default: |
| 16650 | return array; |
| 16651 | } |
| 16652 | |
| 16653 | return array.filter(predicateFn); |
| 16654 | }; |
| 16655 | } |
| 16656 | |
| 16657 | // Helper functions for `filterFilter` |
| 16658 | function createPredicateFn(expression, comparator, matchAgainstAnyProp) { |
nothing calls this directly
no test coverage detected