DEV Community

PWC 353 To each (array) his own

The author found the weekly challenges to be easier than usual, a welcome relief before the holidays. The first task involved finding the maximum word count in a sentence array, solved with a simple one-liner using `split` and `max`. The second challenge required validating coupon codes based on specific criteria. The validation process involved checking code format with regular expressions, name categories using a hash lookup and status using string comparison. Two approaches were explored: explicit indexing and an iterator using `each_arrayref`. The iterator approach resulted in cleaner code despite being less efficient than explicit indexing. The author conducted benchmarking by running multiple iterations using the `Benchmark::cmpthese` function. This performance check revealed that the explicit indexing method was about twice as fast. Finally, the author provided example test case data with expected outputs for thorough testing.
favicon
dev.to
dev.to
Create attached notes ...