Write a Ruby program to check two given arrays of integers and test whether they have the same first element

  • برمجة
  • برمجة روبي

Write a Ruby program to check two given arrays of integers and test whether they have the same first element or they have the same last element. Both arrays length must be 1 or more.

الأجوبة

def check_array(a, b)
   return (a[0] == b[0] || a[a.length-1] == b[b.length-1])
end
print check_array([1, 2, 5], [7, 5]),"\n" 
print check_array([1, 2, 3], [7, 3, 2]),"\n" 
print check_array([1, 2, 4], [1, 4]) 

Output:

true
false
true
هل كان المحتوى مفيد؟

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

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