Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

return symmetric difference of the array javascript

function symmetricDiff(arrary1, array2){
 let symmetricDifference = []; 
  
 symmetricDifference = array1.filter(element => !array2.includes(element))
   .concat(array2.filter(element => !array1.includes(element)))
 return symmetricDifference;
}
Comment

How To Get The Difference Between Two Arrays In JavaScript

function arr_diff (a1, a2) {

    var a = [], diff = [];

    for (var i = 0; i < a1.length; i++) {
        a[a1[i]] = true;
    }

    for (var i = 0; i < a2.length; i++) {
        if (a[a2[i]]) {
            delete a[a2[i]];
        } else {
            a[a2[i]] = true;
        }
    }

    for (var k in a) {
        diff.push(k);
    }

    return diff;
}

console.log(arr_diff(['a', 'b'], ['a', 'b', 'c', 'd']));
console.log(arr_diff("abcd", "abcde"));
console.log(arr_diff("zxc", "zxc"));
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript make alert sound 
Javascript :: react native floating button 
Javascript :: javascript number between values 
Javascript :: javascript loop and array 
Javascript :: stop interval js 
Javascript :: bs modal service close 
Javascript :: js get form inputs 
Javascript :: add parameter to url without reload jquery 
Javascript :: question mark and colon in javascript 
Javascript :: how to cache data in javascript 
Javascript :: foreach in javascript 
Javascript :: merge objects javascript 
Javascript :: float to currency js 
Javascript :: for object 
Javascript :: datatables on row created 
Javascript :: add formdata javascript 
Javascript :: location of release apk in react native 
Javascript :: js read text file line by line 
Javascript :: push an property and value to an object in javascript 
Javascript :: jquery hover event 
Javascript :: get id from queryselector 
Javascript :: bootstrap datepicker mindate today 
Javascript :: how to erase spaces from a string javascript 
Javascript :: set default date today js 
Javascript :: react native textinput no keyboard 
Javascript :: write json file c# 
Javascript :: automatically select current date in date input javascript 
Javascript :: javascript join list of string 
Javascript :: authentication in strapi 
Javascript :: redirect in vue 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =