带有条件语句的嵌套过滤器,没有像我想要的那样显示


function destroyer(...arr) {
let org = arr[0];
let cut = arr.splice(1,);
let result = [];
let des = org.filter( v =>
cut.filter( j => {
if (v == j) {
false
}
else {
result.push(v)
}
})
)
console.log(result)
}
destroyer([1, 2, 3, 2, 3],4, 2, 3)

好的,所以我正在网上学习如何做"中间"问题,我不知道为什么这不起作用。我想把最初的数组打散销毁,分成两部分组织和切割。我需要删除组织中显示在cut中的任何值。所以我在一个过滤器中嵌套过滤器,将匹配的v和j设置为false,并推送不匹配的内容,我得到了。[1,1,1,2,3,3,2,3,3]

如果您所要做的只是从数组中删除数组外的值,那么这应该是一个简单的过滤器用法。

function destroyer( org, ...cut ) {
let result = org.filter( v => cut.indexOf( v ) < 0 );

console.log( result );
}
destroyer( [ 1, 2, 3, 2, 3 ], 4, 2, 3 );

最新更新