How to impress the locals...
Randal L. Schwartz
merlyn at stonehenge.com
Sat Jul 16 22:08:48 UTC 2005
>>>>> "Alan" == Alan Lovejoy <squeak-dev.sourcery at forum-mail.net> writes:
Alan> #(9 2 4 12 -3 44) inject: Infinity positive into: [:min :value |
Alan> value >= min ifTrue: [min] ifFalse: [value]]
Alan> #(9 2 4 12 -3 44) inject: Infinity negative into: [:max :value |
Alan> value <= max ifTrue: [max] ifFalse: [value]]
Those look overly complicated:
s := #(9 2 4 12 -3 44).
max := s allButFirst inject: s first into: [:r :i | r max: i]
If you don't like the allButFirst copy, you can use the original
set anyway, since the identity element of "s first" will max with
itself just fine.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
More information about the Squeak-dev
mailing list
|