wondering of there is a built in function to spit out the last n entires of an ordered collection.. in a pinch, this worked: | ipcount newList | ipcount := self repository size. newList := OrderedCollection new. (ipcount - anInteger) to: ipcount do: [ :n | newList add: (self repository at: n) ].
but i am guessing that is a total kludge... thanks! --
---- peace, sergio photographer, journalist, visionary
http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
On 4/11/2010 8:14 PM, sergio_101 wrote:
wondering of there is a built in function to spit out the last n entires of an ordered collection.. in a pinch, this worked: | ipcount newList | ipcount := self repository size. newList := OrderedCollection new. (ipcount - anInteger) to: ipcount do: [ :n | newList add: (self repository at: n) ].
but i am guessing that is a total kludge...
Use #last: e.g.,
collection := (1 to: 50) asOrderedCollection. collection last: 5. "45 .. 50"
There is also #first: and the companions #allButFirst: and #allButLast:, e.g.,
collection first: 5. "1 .. 5" collection allButFirst: 5. "6 .. 50" collection allButLast: 5. "1 .. 45"
And of course these work with strings too, thus:
'image.bmp' last: 4. ".bmp" 'image.bmp' allButLast: 4. "image"
Cheers, - Andreas
Cheers, - Andreas
dge...
Use #last: e.g.,
wow!
thanks!
i glossed right past that!
i saw 'last'.. not 'last:'
thanks again!
Use #last: e.g.,
i take that back...
looking again, the reason i didn't see that was because it's inherited from SequenceableCollection..
next time i go looking for functions, i will look up the hierarchy if i don't immediately see it..
thanks again..
beginners@lists.squeakfoundation.org