“diff dos matrices javascript” Código de respuesta

Diferencia de JavaScript entre dos matrices

let difference = arr1.filter(x => !arr2.includes(x));
Fragile Fish

diff dos matrices javascript

function diffArray(arr1, arr2) {
  return arr1
    .concat(arr2)
    .filter(item => !arr1.includes(item) || !arr2.includes(item));
}
Yawning Yacare

JavaScript obtenga la diferencia de matriz

function arrayDiff (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;
}
//usage:
console.log(arrayDiff(['red', 'white','green'], [ 'red','white', 'blue']));//["green", "blue"]
Grepper

Cómo comparar dos matrices JavaScript

function arraysAreIdentical(arr1, arr2){
    if (arr1.length !== arr2.length) return false;
    for (var i = 0, len = arr1.length; i < len; i++){
        if (arr1[i] !== arr2[i]){
            return false;
        }
    }
    return true; 
}
Spotless Shrew

Compare dos matriz en JavaScript

let arr1 = [1, 4, 7, 4, 2, 3];
let arr2 = [1, 2, 3, 4, 7, 18];

const is_same = arr1.length == arr2.length &&
  (arr1.every((currElem)=>{
    if(arr2.indexOf(currElem)> -1){
      return (currElem == arr2[arr2.indexOf(currElem)]);
    }return false
  })
)
console.log(is_same)
Gentle Gerenuk

Respuestas similares a “diff dos matrices javascript”

Preguntas similares a “diff dos matrices javascript”

Más respuestas relacionadas con “diff dos matrices javascript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código