只会一些基础的HTML,然后不是很理解,不要太高大上,就只要简单的用function,for语句来给我提供思路,谢谢了。
/**
* 返回两个集合的交集
*/
function intersection(thisSet, otherSet) {
//初始化一个新集合,用于表示交集。
var interSectionSet = new Set();
//将当前集合转换为数组
var values = Array.from(thisSet);
//遍历数组,如果另外一个集合也有该元素,则interSectionSet加入该元素。
for (var i = 0; i < values.length; i++) {
if (otherSet.has(values[i])) {
interSectionSet.add(values[i])
}
}
return interSectionSet;
};
/**
* 返回两个集合的差集
*/
function difference(thisSet, otherSet) {
//初始化一个新集合,用于表示差集。
var differenceSet = new Set();
//将当前集合转换为数组
var values = Array.from(thisSet);
//遍历数组,如果另外一个集合没有该元素,则differenceSet加入该元素。
for (var i = 0; i < values.length; i++) {
if (!otherSet.has(values[i])) {
differenceSet.add(values[i])
}
}
return differenceSet;
};
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!