Write a JavaScript program to compare two objects to determine if the first one contains equivalent property values to the second one, based on a provided function
- برمجة جافاسكربت java script
- برمجة
- 2021-06-03
- ahmadghneem
الأجوبة
const matchesWith = (obj, source, fn) =>
Object.keys(source).every(
key =>
obj.hasOwnProperty(key) && fn
? fn(obj[key], source[key], key, obj, source)
: obj[key] == source[key]
);
const isGreeting = val => /^h(?:i|ello)$/.test(val);
console.log(matchesWith(
{ greeting: 'hello' },
{ greeting: 'hi' },
(oV, sV) => isGreeting(oV) && isGreeting(sV)
));
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال