Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Averages-Mode/Jq/averages-mode-1.jq
Normal file
19
Task/Averages-Mode/Jq/averages-mode-1.jq
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# modes/0 produces an array of [value, count]
|
||||
# in increasing order of count:
|
||||
def modes:
|
||||
sort | reduce .[] as $i ([];
|
||||
# state variable is an array of [value, count]
|
||||
if length == 0 then [ [$i, 1] ]
|
||||
elif .[-1][0] == $i then setpath([-1,1]; .[-1][1] + 1)
|
||||
else . + [[$i,1]]
|
||||
end )
|
||||
| sort_by( .[1] );
|
||||
|
||||
# mode/0 outputs a stream of the modal values;
|
||||
# if the input array is empty, the output stream is also empty.
|
||||
def mode:
|
||||
if length == 0 then empty
|
||||
else modes as $modes
|
||||
| $modes[-1][1] as $count
|
||||
| $modes[] | select( .[1] == $count) | .[0]
|
||||
end;
|
||||
3
Task/Averages-Mode/Jq/averages-mode-2.jq
Normal file
3
Task/Averages-Mode/Jq/averages-mode-2.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[1,2,3,1,2,1] | mode # => 1
|
||||
[1,2,3,1,2,1,2] | mode # => 1 2
|
||||
[1.1, 1.2, 1.3, 1.1, 1.2, 1.1] | mode) # => 1.1
|
||||
Loading…
Add table
Add a link
Reference in a new issue