Pregunta de entrevista de BYJU'S

Write a function for the following JavaScript code? const obj1 = { age: 25, color: "white", weight: true }; const obj2 = { color: "white", weight: true } const obj3 = { age: 26, color: "white", weight: true } console.log(matches(obj1, obj2)); // true console.log(matches(obj2, obj1)); // false console.log(matches(obj3, obj1)); // false console.log(matches(obj3, obj2)); // true

Respuesta de la entrevista

Anónimo

30 de sept de 2020

function matches(obj1, obj2){ for(let o in obj2){ if(!(obj1[o] && obj1[o]===obj2[o])) return false; } return true; }