- // Interestingly, the regular maxItem is twice as fast as this much more elegant version.
- // However, you can learn a lot by trying to solve and reimplement common methods with e.g. inject.
- f = {|a| a.inject(a.first, {|last, current|
- max(current, last)
- })}
- // an example array
- a = {100.0.rand2}!1000
- // evaluating the inject method
- f.(a)
- // benchmark
- {100.do{f.(a)}}.bench
- {100.do{a.maxItem}}.bench