Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Write a function to identify objects in the first array, which matches all the attribute and value pairs in the second object

Return type should be a array.


findMatches(
    [
        {"X" : "1", "Y" : "2","Z" : "4", "P" : "5"},
        {"X" : "2", "Y" : "2","Z" : "4", "P" : "5"},
        {"X" : "1", "Y" : "2","Z" : "9", "P" : "6"}
    ],
    {"X":"1", "Y":"2"}
);

Should return

[
    {"X" : "1", "Y" : "2","Z" : "4", "P" : "5"}, 
    {"X" : "1", "Y" : "2","Z" : "9", "P" : "6"}
]

Answer should be valid for any given input.

function findMatches(arr ,obj) {
    return [];
}
findMatches(
    [
        {"X" : "1", "Y" : "2","Z" : "4", "P" : "5"}, 
        {"X" : "2", "Y" : "2","Z" : "4", "P" : "5"}, 
        {"X" : "1", "Y" : "2","Z" : "9", "P" : "6"}
    ], 
    {"X":"1", "Y":"2"}
);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can simply achieve it by using Array.filter() method.

Demo :

const arr = [
  {"X" : "1", "Y" : "2","Z" : "4", "P" : "5"},
  {"X" : "2", "Y" : "2","Z" : "4", "P" : "5"},
  {"X" : "1", "Y" : "2","Z" : "9", "P" : "6"}
];

const obj = {"X":"1", "Y":"2"};

function findMatches(arr, obj) {
   return arr.filter((arrayObj) => (arrayObj.X === obj.X) && (arrayObj.Y === obj.Y));
}

const res = findMatches(arr, obj);

console.log(res);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda