source: frontend/node_modules/underscore/modules/uniq.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import isBoolean from './isBoolean.js';
2import cb from './_cb.js';
3import getLength from './_getLength.js';
4import contains from './contains.js';
5
6// Produce a duplicate-free version of the array. If the array has already
7// been sorted, you have the option of using a faster algorithm.
8// The faster algorithm will not work with an iteratee if the iteratee
9// is not a one-to-one function, so providing an iteratee will disable
10// the faster algorithm.
11export default function uniq(array, isSorted, iteratee, context) {
12 if (!isBoolean(isSorted)) {
13 context = iteratee;
14 iteratee = isSorted;
15 isSorted = false;
16 }
17 if (iteratee != null) iteratee = cb(iteratee, context);
18 var result = [];
19 var seen = [];
20 for (var i = 0, length = getLength(array); i < length; i++) {
21 var value = array[i],
22 computed = iteratee ? iteratee(value, i, array) : value;
23 if (isSorted && !iteratee) {
24 if (!i || seen !== computed) result.push(value);
25 seen = computed;
26 } else if (iteratee) {
27 if (!contains(seen, computed)) {
28 seen.push(computed);
29 result.push(value);
30 }
31 } else if (!contains(result, value)) {
32 result.push(value);
33 }
34 }
35 return result;
36}
Note: See TracBrowser for help on using the repository browser.