将两个数组中的非重复值返回到数组中 - JavaScript ES5

问题描述

我正在尝试获得

的返回结果
["a","to","past","adventure","of"]

来自

["a","link","the","past"]
["the","of","link"]

我的返回结果是

["a","link"]

我尝试使用 .includes 方法,但我得到了更奇怪的回报。我肯定错误地使用了语法。我不允许使用 .filter

我的代码

function difference(first,second) {
  const newArray = [];
  for (let i = 0; i < first.length; i++) {
    if (first[i] !== second[i]) {
      newArray.push(first[i]);
    }
  }
  for (let j = 0; j < second.length; j++) {
    if (second[j] !== first[j]) {
      newArray.push(second[j]);
    }
  }
  console.log(newArray);
  return newArray;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)