unique.js 1.0 KB

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