| |
Dondo Land
Bryan Donovan's Weblog
Sunday August 27, 2006 |
|
Rubyquiz has accepted my submission, asking readers to write a class that returns a range of days in a human-readable format. The quiz can be found here.
Here's an excerpt explaining the idea..
If you've ever created a web application that deals with scheduling recurring events, you may have found yourself creating a method to convert a list of days into a more human-readable string.
For example, suppose a musician plays at a certain venue on Monday, Tuesday, Wednesday, and Saturday. You could pass a list of associated day numbers to your object or method, which might return "Mon-Wed, Sat".
The purpose of this quiz is to find the best "Ruby way" to generate this sentence-like string.
[...]
Here are some example lists of days and their expected returned strings:
1,2,3,4,5,6,7: Mon-Sun
1,2,3,6,7: Mon-Wed, Sat, Sun
1,3,4,5,6: Mon, Wed-Sat
2,3,4,6,7: Tue-Thu, Sat, Sun
1,3,4,6,7: Mon, Wed, Thu, Sat, Sun
7: Sun
1,7: Mon, Sun
1,8: ArgumentError
To my surprise, there have already been several submissions with varying ways of solving the problem. This is a good way to learn some Ruby for sure..
(2006-08-27 12:10:46.0/2006-08-27 10:15:06.0)
Permalink
Trackback: http://blogs.sun.com/bdonovan/entry/day_range_rubyquiz
|
|
|
|
| « August 2006 » | | Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|
| | | 1 | | 3 | 4 | | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | | 28 | 29 | 30 | 31 | | | | | | | | | | | | Today |
Today's Page Hits: 25
|