How to return array keys into another array

Travis Griggs tgriggs at key.net
Mon Jun 14 16:55:10 UTC 2004


adrian voss wrote:
> Hello All
> 
> I am quite new to smalltalk and am hoping someone can help me or point 
> me in the right direction as I am quite stumped by this.
> 
> I have an array with elements either being 'free' or 'reserved'.  I am 
> trying to get only the keys for all the element that match 'free' into a 
> new array.
> 
> Thanks for your time.

yourArray keys select: [:i | (yourArray at: i) isFree]

isFree is assumed to be whatever test you use to determine matches for 
'free'.

Being able to ask yourArray for keys is an extension I make in 
VisualWorks (see 
<http://www.cincomsmalltalk.com/userblogs/travis/blogView?showComments=true&entry=3264531132>. 
I don't know if the same extension exists for Squeak already or not.

-- 
Travis Griggs
Objologist
Key Technology
Achille's Heel?!?! What about "Goliath's Forehead"

-----------------------------------------
DISCLAIMER: This email is bound by the terms and conditions described at
http://www.key.net/disclaimer.htm




More information about the Squeak-dev mailing list