zilongxuan001 / LearnFreecode

0 stars 0 forks source link

Diff Two Arrays #324

Open zilongxuan001 opened 6 years ago

zilongxuan001 commented 6 years ago

错误思路

1.过滤掉重复的元素。通过indexOf(),和filter()方法。凡是arr1中元素在arr2中indeOf()不等于-1,则该元素pop给一个变量,同时删除arr2中的该元素。 2.新数组和arr2合并。使用concat()方法。

正确思路

1.合并两个数组。 2.定义一个函数,如果一个元素不在数组1或不在数组2,则返回该元素。 3.通过函数,过滤合并后的数组。

犯的错误

1.idexOf拼写错误。 2.filter(函数名称)中,函数名称无须加上括号。

参考

Rafael Rodriguez的FCC学习记录