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