_baseSortedUniq.js 758 B

12345678910111213141516171819202122232425262728293031
  1. var eq = require('./eq');
  2. /**
  3. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  4. * support for iteratee shorthands.
  5. *
  6. * @private
  7. * @param {Array} array The array to inspect.
  8. * @param {Function} [iteratee] The iteratee invoked per element.
  9. * @returns {Array} Returns the new duplicate free array.
  10. */
  11. function baseSortedUniq(array, iteratee) {
  12. var index = -1,
  13. length = array.length,
  14. resIndex = 0,
  15. result = [];
  16. while (++index < length) {
  17. var value = array[index],
  18. computed = iteratee ? iteratee(value) : value;
  19. if (!index || !eq(computed, seen)) {
  20. var seen = computed;
  21. result[resIndex++] = value === 0 ? 0 : value;
  22. }
  23. }
  24. return result;
  25. }
  26. module.exports = baseSortedUniq;