Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #60004 > unrolled thread
| Started by | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| First post | 2017-05-29 05:48 +0000 |
| Last post | 2017-05-29 05:48 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.forth
Rosetta: Sort an array of composite structures "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-29 05:48 +0000
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Date | 2017-05-29 05:48 +0000 |
| Subject | Rosetta: Sort an array of composite structures |
| Message-ID | <oggcn0$tei$1@gioia.aioe.org> |
> Sort an array of composite structures by a key.
a =
[["gold", "shiny"],
["neon", "inert"],
["sulphur", "yellow"],
["iron", "magnetic"],
["zebra", "striped"],
["star", "brilliant"],
["apple", "tasty"],
["ruby", "red"],
["dice", "random"],
["coffee", "stimulating"],
["book", "interesting"]]
puts a.sort.map{|xs| xs.join " => "}
===>
apple => tasty
book => interesting
coffee => stimulating
dice => random
gold => shiny
iron => magnetic
neon => inert
ruby => red
star => brilliant
sulphur => yellow
zebra => striped
puts a.sort_by(&:last).map{|xs| xs.join " => "}
===>
star => brilliant
neon => inert
book => interesting
iron => magnetic
dice => random
ruby => red
gold => shiny
coffee => stimulating
zebra => striped
apple => tasty
sulphur => yellow
In Forth?
--
New York City: Without Blacks and Mestizos, 90% of Crime Would Disappear.
Actually, the real figures would be even more startling, because Middle
Easterners are falsely categorized as White in the statistics.
nationalvanguard.org/2015/10/new-york-city-without-blacks-and-mestizos-90-of-crime-would-disappear/
Back to top | Article view | comp.lang.forth
csiph-web