We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
type ISimpleArray = Array<number | string> function difference(a: ISimpleArray, b: ISimpleArray) { const long = a.length > b.length ? a : b const short = a.length > b.length ? b : a return long.filter((item) => { return !short.includes(item) }) }
Sorry, something went wrong.
function diff(arr1, arr2) { // 用 firstArr 和 secondArr 来表示传入的参数,均为数组 function getDiff (firstArr, secondArr) { // 设置一个变量用于暂存结果 var result = []; // 逻辑思路是,遍历 firstArr,然后与 secondArr 比较 for (var i = 0; i< firstArr.length; i++) { if (!secondArr.includes(firstArr[i])) { result.push(firstArr[i]); } } // 这个 result 并不是最终的结果。我们需要对传入的参数操作两次,然后把两次的结果合并起来 return result; } return getDiff(arr1, arr2).concat(getDiff(arr2, arr1)); }
function diff(arr1, arr2) { return arr1.filter(e => !arr2.includes(e) ).concat( arr2.filter(e => !arr1.includes(e)) ); }
function diff(arr1, arr2) { return arr1.concat(arr2).filter(e => !arr1.includes(e) || !arr2.includes(e)); }
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: