Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!