On Wed, Nov 20, 2019 at 08:48:50AM +0100, Marcel Taeumel wrote:
Hi, all.
What's the "most idiomatic" way to create an array with 100 random numbers > 0 < 100?
(1 to: 100) collect: [:ea | 100 atRandom] Array streamContents: [:s | 100 timesRepeat: [s nextPut: 100 atRandom]]. ...
If "most idiomatic" means "functionally correct, easy to read, and easy to understand" then I prefer the first:
(1 to: 100) collect: [:ea | 100 atRandom]
I can read it from left to right, and it tells me that I am collecting 100 elements and putting 100 atRandom into each of the 100 elements. It's also simple, just a collect: and nothing more.
Dave