June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,16 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
import system'culture.
|
||||
|
||||
program =
|
||||
[
|
||||
var items := ( "Here", "are", "some", "sample", "strings", "to", "be", "sorted" ).
|
||||
|
||||
console printLine("Unsorted: ", items).
|
||||
|
||||
console printLine("Descending length: ", items clone;
|
||||
sort(:p:n)(p length > n length) ).
|
||||
|
||||
console printLine("Ascending order: ", items clone;
|
||||
sort(:p:n)(p toUpper(invariantLocale) < n toUpper(invariantLocale)) ).
|
||||
].
|
||||
|
|
@ -1,17 +1,7 @@
|
|||
st = """You will rejoice to hear that no disaster has accompanied the
|
||||
commencement of an enterprise which you have regarded with such evil
|
||||
forebodings."""
|
||||
wl = filter(!isempty, split("""You will rejoice to hear that no disaster has accompanied the
|
||||
commencement of an enterprise which you have regarded with such evil
|
||||
forebodings.""", r"\W+"))
|
||||
|
||||
wl = filter(x->length(x)>0, split(st, r"\W+"))
|
||||
|
||||
println("Original List:")
|
||||
for w in wl
|
||||
println(" ", w)
|
||||
end
|
||||
|
||||
wl = sort(wl, by=x->(-length(x), lowercase(x)))
|
||||
|
||||
println("\nSorted List:")
|
||||
for w in wl
|
||||
println(" ", w)
|
||||
end
|
||||
println("Original list:\n - ", join(wl, "\n - "))
|
||||
sort!(wl; by=x -> (-length(x), lowercase(x)))
|
||||
println("\nSorted list:\n - ", join(wl, "\n - "))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
my @strings = <Here are some sample strings to be sorted>;
|
||||
my @sorted_strings = sort { $^a.chars <=> $^b.chars or $^a.lc cmp $^b.lc }, @strings;
|
||||
.say for @sorted_strings;
|
||||
|
||||
# If instead the function you feed to <code>sort</code> is of arity 1, it will do the Schwartzian transform for you, automatically sorting numeric fields numerically, and strings fields stringily:
|
||||
|
||||
say @sorted_strings = sort -> $x { [ $x.chars, $x.lc ] }, @strings;
|
||||
Loading…
Add table
Add a link
Reference in a new issue