September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,18 @@
|
|||
# Sort any array
|
||||
def selection_sort:
|
||||
def swap(i;j): if i == j then . else .[i] as $tmp | .[i] = .[j] | .[j] = $tmp end;
|
||||
length as $length
|
||||
| reduce range(0; $length) as $currentPlace
|
||||
# state: $array
|
||||
( .;
|
||||
. as $array
|
||||
| (reduce range( $currentPlace; $length) as $check
|
||||
# state: [ smallestAt, smallest] except initially [null]
|
||||
( [$currentPlace+1] ;
|
||||
if length == 1 or $array[$check] < .[1]
|
||||
then [$check, $array[$check] ]
|
||||
else .
|
||||
end
|
||||
)) as $ans
|
||||
| swap( $currentPlace; $ans[0] )
|
||||
) ;
|
||||
|
|
@ -0,0 +1 @@
|
|||
[1, 3.3, null, 2, null, [1,{"a":1 }] ] | selection_sort
|
||||
Loading…
Add table
Add a link
Reference in a new issue