unique.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = unique;
  7. var _arrayContainsObject = _interopRequireDefault(require("./arrayContainsObject"));
  8. var _ParseObject = _interopRequireDefault(require("./ParseObject"));
  9. /**
  10. * Copyright (c) 2015-present, Parse, LLC.
  11. * All rights reserved.
  12. *
  13. * This source code is licensed under the BSD-style license found in the
  14. * LICENSE file in the root directory of this source tree. An additional grant
  15. * of patent rights can be found in the PATENTS file in the same directory.
  16. *
  17. * @flow
  18. */
  19. function unique
  20. /*:: <T>*/
  21. (arr
  22. /*: Array<T>*/
  23. )
  24. /*: Array<T>*/
  25. {
  26. var uniques = [];
  27. arr.forEach(function (value) {
  28. if (value instanceof _ParseObject.default) {
  29. if (!(0, _arrayContainsObject.default)(uniques, value)) {
  30. uniques.push(value);
  31. }
  32. } else {
  33. if (uniques.indexOf(value) < 0) {
  34. uniques.push(value);
  35. }
  36. }
  37. });
  38. return uniques;
  39. }