美文网首页
javaScript 判断两个数组为包含, 半包含, 不包含

javaScript 判断两个数组为包含, 半包含, 不包含

作者: NanaCti | 来源:发表于2020-05-09 18:06 被阅读0次
// 判断数组包含状态
export const isContained = (totalList: [], sectionList: []):number => {
  const total = totalList.concat(sectionList);
  const setTotal = new Set(total);
  const repeat = total.length - setTotal.size;
  if (repeat === 0) return 0;// totalList里不包含sectionList的任何项
  if (repeat < sectionList.length) return 1;// totalList里包含sectionList的项,不包含全部
  if (repeat === sectionList.length) return 2;// totalList里包含sectionList的全部项
  return -1;// 错误
}

相关文章

网友评论

      本文标题:javaScript 判断两个数组为包含, 半包含, 不包含

      本文链接:https://www.haomeiwen.com/subject/vlhlnhtx.html