Common sorted list: Difference between revisions
Content added Content deleted
(Added Quackery.) |
|||
Line 541: | Line 541: | ||
<pre>[1, 3, 4, 5, 7, 8, 9]</pre> |
<pre>[1, 3, 4, 5, 7, 8, 9]</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
Assuming the input is a single array of arrays, we can simply chain the `add` and `unique` filters: |
|||
<lang jq>jq -nc '[[5,1,3,8,9,4,8,7], [3,5,9,8,4], [1,3,7,9]] | add | unique'</lang> |
|||
{{out}} |
|||
<pre> |
|||
[1,3,4,5,7,8,9] |
|||
</pre> |
|||
If the arrays are presented individually in an external stream, we could use the `-s` command-line option. |
|||
Alternatively, here's a stream-oriented version of `add` that could be used: |
|||
<lang jq>def add(s): reduce s as $x (null; . + $x);</lang> |
|||
For example: |
|||
<lang jq>jq -nc ' |
|||
def add(s): reduce s as $x (null; . + $x); |
|||
add(inputs) | unique' <<< '[5,1,3,8,9,4,8,7] [3,5,9,8,4] [1,3,7,9]'</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<lang julia> |
<lang julia> |