Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

28
Vistas
Delete Duplicate from Two arrays and display one of the arrays in javascript

I want delete duplicate array from two arrays, but just show one of array, how I can do it ? I want result [1, 4]

const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3, 5, 6]
function arrayUniq(arr1, arr2) {
 enter code here
    }
7 months ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

As @Titus said, just filter the array comparing if one of them have repeated values.

const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3, 5, 6];
function arrayUniq(arr1, arr2) {
 const arrays = [...arr1,...arr2]
 return arrays.filter(a=> !arr2.includes(a))
}
console.log(arrayUniq(arr1,arr2))

7 months ago · Santiago Gelvez Denunciar

0

// remove duplicates from arr1 and arr2
function arrayUniq(arr1, arr2) {
    let result = [];

    // Find unique elements in arr1 & push them into result
    arr1.forEach((e) => (arr2.find((f) => f === e) ? null : result.push(e)));

    // Find unique elements in arr2 & push them into result
    arr2.forEach((e) => (arr1.find((f) => f === e) ? null : result.push(e)));

    return result;
}

console.log(arrayUniq(arr1, arr2));
7 months ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.