June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,38 +1,17 @@
|
|||
type Pair{T<:String}
|
||||
name::T
|
||||
value::T
|
||||
end
|
||||
lst = Pair[Pair("gold", "shiny"),
|
||||
Pair("neon", "inert"),
|
||||
Pair("sulphur", "yellow"),
|
||||
Pair("iron", "magnetic"),
|
||||
Pair("zebra", "striped"),
|
||||
Pair("star", "brilliant"),
|
||||
Pair("apple", "tasty"),
|
||||
Pair("ruby", "red"),
|
||||
Pair("dice", "random"),
|
||||
Pair("coffee", "stimulating"),
|
||||
Pair("book", "interesting")]
|
||||
|
||||
Base.show(a::Pair) = @sprintf "%s => %s" a.name a.value
|
||||
|
||||
x = Pair[Pair("gold", "shiny"),
|
||||
Pair("neon", "inert"),
|
||||
Pair("sulphur", "yellow"),
|
||||
Pair("iron", "magnetic"),
|
||||
Pair("zebra", "striped"),
|
||||
Pair("star", "brilliant"),
|
||||
Pair("apple", "tasty"),
|
||||
Pair("ruby", "red"),
|
||||
Pair("dice", "random"),
|
||||
Pair("coffee", "stimulating"),
|
||||
Pair("book", "interesting")]
|
||||
|
||||
|
||||
println("x, the original list of pairs: ")
|
||||
for p in x
|
||||
println(" ", show(p))
|
||||
end
|
||||
|
||||
println()
|
||||
println("x sorted by name:")
|
||||
x = sort(x, by=a->a.name)
|
||||
for p in x
|
||||
println(" ", show(p))
|
||||
end
|
||||
|
||||
println()
|
||||
println("x sorted by value:")
|
||||
x = sort(x, by=a->a.value)
|
||||
for p in x
|
||||
println(" ", show(p))
|
||||
end
|
||||
println("The original list: \n - ", join(lst, "\n - "))
|
||||
sort!(lst; by=first)
|
||||
println("\nThe list, sorted by name: \n - ", join(lst, "\n - "))
|
||||
sort!(lst; by=last)
|
||||
println("\nThe list, sorted by value: \n - ", join(lst, "\n - "))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue