-2

I've seen more than one question solving this but when applying them it didn't work for me, please help me solve this. I've written my code according to this question

    let difference = selectedStores.filter(selectedStore => {
      alreadySyncedStores.filter(productSyncedStores => {
        console.log('productSyncedStores', productSyncedStores);
        console.log('selectedStore', selectedStore);
        console.log('result ', !productSyncedStores.includes(selectedStore));
        !productSyncedStores.includes(selectedStore)
      })
    });
    console.log('>>difference<<<', difference)

both arrays and console results are reflected in the images below thanks in advance. enter image description here

expected result is : difference = ['100000000713']

  • In what way is your code not working as expected? Please elaborate on the specific problem you are observing and what debugging you have done. To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Aug 05 '22 at 10:49

1 Answers1

1

You can use this function to get the desired output

Suppose you have two array arr1 and arr2

var arr1 = ['12', '32', '54'];
var arr2 = ['14', '32', '21'];

function GetDifference(arr1, arr2) {
  var diffArr = [];

  arr1.forEach(function(index, value) {
    if (arr2.indexOf(index) == -1) {
      diffArr.push(index);
    }
  });

  arr2.forEach(function(index, value) {
    if (arr1.indexOf(index) == -1 && diffArr.indexOf(index) == -1) {
      diffArr.push(index);
    }
  });

  return diffArr;
}

console.log(GetDifference(arr1, arr2))

You will get ['12', '54', '14', '21'] as output.

kennarddh
  • 2,186
  • 2
  • 6
  • 21
Vinay
  • 11
  • 2