只会一些基础的HTML,然后不是很理解,不要太高大上,就只要简单的用function,for语句来给我提供思路,谢谢了。
2条回答 默认 最新
- CSDN专家-sinJack 2022-03-20 15:30关注
/** * 返回两个集合的交集 */ 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; };
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报