Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,10 @@
|
|||
;; sorting (name value) by name - Ignoring case
|
||||
(define (name a) (first a))
|
||||
(define( sort-proc a b)
|
||||
(string-ci<? (name a) (name b)))
|
||||
|
||||
(define people
|
||||
'(("😎" -42) ("albert" 33) ("Simone" 44) ("Antoinette" 42) ("elvis" 666) ("😃" 1000)))
|
||||
|
||||
(list-sort sort-proc people)
|
||||
→ (("albert" 33) ("Antoinette" 42) ("elvis" 666) ("Simone" 44) ("😃" 1000) ("😎" -42))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import algorithm, future
|
||||
|
||||
var people = @{"joe": 120, "foo": 31, "bar": 51}
|
||||
sort(people, (x,y) => cmp(x[0], y[0]))
|
||||
echo people
|
||||
|
|
@ -0,0 +1 @@
|
|||
[["Joe",5531], ["Adam",2341], ["Bernie",122], ["David",19]] sortBy(#first) println
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
constant NAME = 1, COLOUR = 2
|
||||
function compare_names(sequence a, sequence b)
|
||||
return compare(a[NAME],b[NAME])
|
||||
end function
|
||||
function compare_colour(sequence a, sequence b)
|
||||
return compare(a[COLOUR],b[COLOUR])
|
||||
end function
|
||||
|
||||
sequence s
|
||||
s = { { "grass", "green" },
|
||||
{ "snow", "white" },
|
||||
{ "sky", "blue" },
|
||||
{ "cherry", "red" } }
|
||||
|
||||
?custom_sort(routine_id("compare_names"),s)
|
||||
?custom_sort(routine_id("compare_colour"),s)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# Declare an array of pairs
|
||||
var people = [['joe', 120], ['foo', 31], ['bar', 51]];
|
||||
|
||||
# Sort the array in-place by name
|
||||
people.sort! {|a,b| a[0] <=> b[0] };
|
||||
|
||||
# Alternatively, we can use the `.sort_by{}` method
|
||||
var sorted = people.sort_by { |item| item[0] };
|
||||
|
||||
# Display the sorted array
|
||||
say people;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def example:
|
||||
[
|
||||
{"name": "Joe", "value": 3},
|
||||
{"name": "Bill", "value": 4},
|
||||
{"name": "Alice", "value": 20},
|
||||
{"name": "Harry", "value": 3}
|
||||
];
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# To sort the array:
|
||||
# example | sort_by(.name)
|
||||
|
||||
# To abbreviate the results, we will just show the names after sorting:
|
||||
|
||||
example | sort_by(.name) | map( .name )
|
||||
|
|
@ -0,0 +1 @@
|
|||
def quicksort_by(f): quicksort( (.[0]|f) <= (.[1]|f) );
|
||||
|
|
@ -0,0 +1 @@
|
|||
example | quicksort_by(.name) | map( .name )
|
||||
Loading…
Add table
Add a link
Reference in a new issue