Write a Ruby program to check whether first and the last element are the same of an given array of integers

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

Write a Ruby program to check whether first and the last element are the same of an given array of integers. The array length must be 1 or more.

الأجوبة

def check_string(my_string, my_substr)
    if my_string.include? my_substr
      return "Substring present in the string."
   else
      return "Substring not present in the string."
   end
end
print check_string("JavaScript","Script")
print "\n",check_string("JavaScript","Scriptt")

Output:

Substring present in the string.
Substring not present in the string.
هل كان المحتوى مفيد؟

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

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