Projekt

Obecné

Profil

Stáhnout (1013 Bajtů) Statistiky
| Větev: | Revize:
1
var baseIteratee = require('./_baseIteratee'),
2
    baseUniq = require('./_baseUniq');
3

    
4
/**
5
 * This method is like `_.uniq` except that it accepts `iteratee` which is
6
 * invoked for each element in `array` to generate the criterion by which
7
 * uniqueness is computed. The order of result values is determined by the
8
 * order they occur in the array. The iteratee is invoked with one argument:
9
 * (value).
10
 *
11
 * @static
12
 * @memberOf _
13
 * @since 4.0.0
14
 * @category Array
15
 * @param {Array} array The array to inspect.
16
 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
17
 * @returns {Array} Returns the new duplicate free array.
18
 * @example
19
 *
20
 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
21
 * // => [2.1, 1.2]
22
 *
23
 * // The `_.property` iteratee shorthand.
24
 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
25
 * // => [{ 'x': 1 }, { 'x': 2 }]
26
 */
27
function uniqBy(array, iteratee) {
28
  return (array && array.length) ? baseUniq(array, baseIteratee(iteratee, 2)) : [];
29
}
30

    
31
module.exports = uniqBy;
(561-561/590)