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
  • برمجة

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.

الأجوبة

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)
));
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...