uniq.js 337 B

1234567891011121314151617181920
  1. var each = require('./each')
  2. var includes = require('./includes')
  3. /**
  4. * 数组去重
  5. *
  6. * @param {Array} array 数组
  7. * @return {Array}
  8. */
  9. function uniq (array) {
  10. var result = []
  11. each(array, function (value) {
  12. if (!includes(result, value)) {
  13. result.push(value)
  14. }
  15. })
  16. return result
  17. }
  18. module.exports = uniq