es6实现并集 差集 交集

并集(俩个数组合并并且去重)
let arr1=[1,2,3,1,2,3,NaN,true,undefined,null];
   let arr2=[14,5,4,,3,NaN,true,NaN,null];
    function bj(ary1,ary2) {
        //合并,[...ary1,...ary2]
        //去重 new Set([...ary1,...ary2])
        //变成数组 [...new Set([...ary1,...ary2])];
        return [...new Set([...ary1,...ary2])];
    }
    bj(arr1,arr2);
交集(相同的部分)
function jj(ary1,ary2) {
    return ary1.filter((item)=>{
        return ary2.includes(item);
    })
}

console.log(jj(arr1, arr2));
差集() 去除并集中交集部分
function cj(ary1,ary2) {
    return bj(ary1,ary2).filter((item)=>{
        return !jj(ary1,ary2).includes(item);
    })
}

console.log(cj(arr1, arr2));
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个使用ES6实现动态悬浮窗组件的示例代码: ```javascript class FloatWindow { constructor({ width, height, backgroundColor }) { this.width = width || 200; this.height = height || 200; this.backgroundColor = backgroundColor || '#FFF'; this.isDragging = false; this.mouseOffsetX = 0; this.mouseOffsetY = 0; this.element = this.createFloatWindow(); this.addEventListeners(); } createFloatWindow() { const floatWindow = document.createElement('div'); floatWindow.style.position = 'absolute'; floatWindow.style.width = `${this.width}px`; floatWindow.style.height = `${this.height}px`; floatWindow.style.backgroundColor = this.backgroundColor; return floatWindow; } addEventListeners() { this.element.addEventListener('mousedown', (event) => { this.isDragging = true; this.mouseOffsetX = event.clientX - this.element.offsetLeft; this.mouseOffsetY = event.clientY - this.element.offsetTop; }); document.addEventListener('mousemove', (event) => { if (this.isDragging) { this.element.style.left = `${event.clientX - this.mouseOffsetX}px`; this.element.style.top = `${event.clientY - this.mouseOffsetY}px`; } }); document.addEventListener('mouseup', () => { this.isDragging = false; }); } show() { document.body.appendChild(this.element); } hide() { document.body.removeChild(this.element); } } ``` 使用该组件时,可以通过传入一个配置对象来设置悬浮窗的大小和背景颜色: ```javascript const floatWindow = new FloatWindow({ width: 300, height: 300, backgroundColor: 'lightblue' }); floatWindow.show(); ``` 然后调用`show()`方法即可在页面中显示悬浮窗,调用`hide()`方法可以将悬浮窗从页面中移除。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值