includeArrays.js 559 B

12345678910111213141516171819202122232425
  1. var isArray = require('./isArray')
  2. var includes = require('./includes')
  3. /**
  4. * 判断数组是否包含另一数组
  5. *
  6. * @param {Array} array1 数组
  7. * @param {Array} array2 被包含数组
  8. * @return {Boolean}
  9. */
  10. function includeArrays (array1, array2) {
  11. var len
  12. var index = 0
  13. if (isArray(array1) && isArray(array2)) {
  14. for (len = array2.length; index < len; index++) {
  15. if (!includes(array1, array2[index])) {
  16. return false
  17. }
  18. }
  19. return true
  20. }
  21. return includes(array1, array2)
  22. }
  23. module.exports = includeArrays