index.js 512 B

12345678910111213141516171819202122232425262728
  1. /*!
  2. * array-unique <https://github.com/jonschlinkert/array-unique>
  3. *
  4. * Copyright (c) 2014-2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. module.exports = function unique(arr) {
  9. if (!Array.isArray(arr)) {
  10. throw new TypeError('array-unique expects an array.');
  11. }
  12. var len = arr.length;
  13. var i = -1;
  14. while (i++ < len) {
  15. var j = i + 1;
  16. for (; j < arr.length; ++j) {
  17. if (arr[i] === arr[j]) {
  18. arr.splice(j--, 1);
  19. }
  20. }
  21. }
  22. return arr;
  23. };