Ruby Basic Exercises: Compute the absolute difference between n and 33
Ruby Basic: Exercise-17 with Solution
Write a Ruby program to compute the absolute difference between n and 33 and return double the absolute difference if n is over 33.
def diff_33(n) n > 33 ? ((n-33)*2).abs : (n-33).abs end print diff_33(47),"\n" print diff_33(17)
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