December 22, 2024

Answer to Collections Q10

 

mountainsOfTheWorld := SortedCollection new.
arrayOfMountains do:
   [: each |
        each keysAndValuesDo:
               [: name :height |
                   mountainsOfTheWorld add: name
               ]
   ].
mountainsOfTheWorld keysAndValuesDo:
    [: index :name | (index<= 3)
           ifTrue: [Dialog warn: name]
    ]

Or the final line can be replaced with:

1 to: 3 do:
    [:index | Dialog warn:
                (mountainsOfTheWorld at: index)
    ]

The first string in the sorted collection will be 'Aconagua'

 

Back to « Collection Questions 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Up to top of page