Skip to main content
[Edit removed during grace period]
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31
added 10 characters in body
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31

Another way to solve the problem

function diffArray(arr1, arr2) { return arr1.concat(arr2).filter(function (val) { if (!(arr1.includes(val) && arr2.includes(val))) return val; }); } diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Also, you can use ES6+arrow function syntax:

const diffArray = (arr1, arr2) => arr1.concat(arr2) .filter(val => !(arr1.includes(val) && arr2.includes(val))); diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Another way to solve the problem

function diffArray(arr1, arr2) { return arr1.concat(arr2).filter(function (val) { if (!(arr1.includes(val) && arr2.includes(val))) return val; }); } diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Also, you can use ES6+ syntax:

const diffArray = (arr1, arr2) => arr1.concat(arr2) .filter(val => !(arr1.includes(val) && arr2.includes(val))); diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Another way to solve the problem

function diffArray(arr1, arr2) { return arr1.concat(arr2).filter(function (val) { if (!(arr1.includes(val) && arr2.includes(val))) return val; }); } diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Also, you can use arrow function syntax:

const diffArray = (arr1, arr2) => arr1.concat(arr2) .filter(val => !(arr1.includes(val) && arr2.includes(val))); diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 
added 233 characters in body
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31

Another way to solve the problem

function diffArray(arr1, arr2) { return arr1.concat(arr2).filter(function (val) { if (!(arr1.includes(val) && arr2.includes(val))) return val; }); } diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Also, you can use ES6+ syntax:

const diffArray = (arr1, arr2) => arr1.concat(arr2) .filter(val => !(arr1.includes(val) && arr2.includes(val))); diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Another way to solve the problem

function diffArray(arr1, arr2) { return arr1.concat(arr2).filter(function (val) { if (!(arr1.includes(val) && arr2.includes(val))) return val; }); } diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Another way to solve the problem

function diffArray(arr1, arr2) { return arr1.concat(arr2).filter(function (val) { if (!(arr1.includes(val) && arr2.includes(val))) return val; }); } diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 

Also, you can use ES6+ syntax:

const diffArray = (arr1, arr2) => arr1.concat(arr2) .filter(val => !(arr1.includes(val) && arr2.includes(val))); diffArray([1, 2, 3, 7], [3, 2, 1, 4, 5]); // return [7, 4, 5] 
deleted 108 characters in body
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31
Loading
added 2 characters in body
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31
Loading
deleted 33 characters in body
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31
Loading
Source Link
Yurii Holskyi
  • 968
  • 1
  • 14
  • 31
Loading