lenorewei
12/16/2017 - 11:59 AM

判断一个字符串数组是否另一个字符串数组的子集

export function subset (current, target) {
	if (!current instanceof Array) {
		if (current[0] === '!') {
			return target.indexOf(current.slice(1)) < 0
		}
		return target.indexOf(current) > -1
	}
	return current.reduce((res, item) => {
		let currentRes
		if (item[0] === '!') {
			currentRes = target.indexOf(item.slice(1)) < 0
		} else {
			currentRes = target.indexOf(item) > -1
		}
		return res && currentRes
	}, true)
}