Min And Max Of Tokens In A String
MartinPacker 11000094DH Visits (738)
A couple of days ago I had a need to take a REXX string comprising space-separated numbers and find their minimum and maximum values. Here's the technique I used.
(When I say "space-separated" there can be one or more spaces between the numbers, but there has to be at least one.)
The solution has three components:
My need is relatively low volume, so the "health warning" about INTERPRET's performance is hardly relevant for my use case.
Here's the code:
It's relatively straightforward, taking a list of numbers and returning the minimum and maximum. You'll notice it doesn't check that the tokens really are numbers. If I were to extend it I'd probably check for two SLR conditions: Overflow ("*" or similar) and Missing Value ("---" or similar). I'd probably take some of the "List Comprehension" stuff I talked about in Dragging REXX Into The 21st Century? and apply it to the list.
And my code uses this to decide if I have a range of values or just a single one. In the former case it turns the pair of numbers into e.g. "1-5" and the latter just e.g. "4".
Of course there are other ways to do minimum and maximum for a list of numbers but this one seems the simplest and most elegant to me. "6 months later me" might take a different view.