Add a unique function.
This commit is contained in:
1 parent
c8bbfed041
commit
fadeb66365
3 files changed
+17
No files matched your search
@@ -295,6 +295,7 @@ static const char* jq_builtins[] = {
|
||||
"def select(f): if f then . else empty end;",
|
||||
"def sort_by(f): _sort_by_impl(map([f]));",
|
||||
"def group_by(f): _group_by_impl(map([f]));",
|
||||
"def unique: group_by(.) | map(.[0]);",
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -542,6 +542,18 @@ sections:
|
||||
input: '[{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]'
|
||||
output: ['[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]']
|
||||
|
||||
- title: `unique`
|
||||
body: |
|
||||
|
||||
The `unique` function takes as input an array and produces
|
||||
an array of the same elements, in sorted order, with
|
||||
duplicates removed.
|
||||
|
||||
examples:
|
||||
- program: 'unique'
|
||||
input: '[1,2,5,3,5,3,1,3]'
|
||||
output: ['[1,2,3,5]']
|
||||
|
||||
- title: `contains`
|
||||
body: |
|
||||
|
||||
|
||||
@@ -448,3 +448,7 @@ sort
|
||||
[{"a": 4, "b": 1, "c": 3}, {"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 3}, {"a": 1, "b": 4, "c": 14}]
|
||||
[[{"a": 4, "b": 1, "c": 3}], [{"a": 0, "b": 2, "c": 43}], [{"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}]]
|
||||
[[{"a": 1, "b": 4, "c": 14}, {"a": 0, "b": 2, "c": 43}], [{"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}]]
|
||||
|
||||
unique
|
||||
[1,2,5,3,5,3,1,3]
|
||||
[1,2,3,5]
|
||||
Reference in new issue
Block a user