1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Reverse function. Closes #94.

This commit is contained in:
Stephen Dolan
2013-05-16 14:25:28 +01:00
parent a1e4dfa324
commit 919292764a
2 changed files with 11 additions and 0 deletions

View File

@@ -562,6 +562,7 @@ static const char* const jq_builtins[] = {
"def to_entries: [keys[] as $k | {key: $k, value: .[$k]}];", "def to_entries: [keys[] as $k | {key: $k, value: .[$k]}];",
"def from_entries: map({(.key): .value}) | add;", "def from_entries: map({(.key): .value}) | add;",
"def with_entries(f): to_entries | map(f) | from_entries;", "def with_entries(f): to_entries | map(f) | from_entries;",
"def reverse: [.[length - 1 - range(0;length)]];",
}; };

View File

@@ -718,6 +718,16 @@ sections:
input: '[1,2,5,3,5,3,1,3]' input: '[1,2,5,3,5,3,1,3]'
output: ['[1,2,3,5]'] output: ['[1,2,3,5]']
- title: `reverse`
body: |
This function reverses an array.
examples:
- program: 'reverse'
input: '[1,2,3,4]'
output: ['[4,3,2,1]']
- title: `contains` - title: `contains`
body: | body: |