Ruby Array Exercises: Check two given arrays of integers and test whether they have the same first element or they have the same last element
Ruby Array: Exercise-7 with Solution
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 == b || 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])
true false true
Ruby Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework