summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2013-05-16 14:25:28 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2013-05-16 14:25:28 +0100
commit919292764a1ba57507ab4c93e732d2037a2ffa14 (patch)
tree31a52b58b021626b0123c6e8ef94dd518626777b
parenta1e4dfa32412457e03dd0e4e4c2ac17eca02c4f8 (diff)
Reverse function. Closes #94.
-rw-r--r--builtin.c1
-rw-r--r--docs/content/3.manual/manual.yml10
2 files changed, 11 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index 47c13865..48d71109 100644
--- a/builtin.c
+++ b/builtin.c
@@ -562,6 +562,7 @@ static const char* const jq_builtins[] = {
"def to_entries: [keys[] as $k | {key: $k, value: .[$k]}];",
"def from_entries: map({(.key): .value}) | add;",
"def with_entries(f): to_entries | map(f) | from_entries;",
+ "def reverse: [.[length - 1 - range(0;length)]];",
};
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml
index e5fff391..7038b5fc 100644
--- a/docs/content/3.manual/manual.yml
+++ b/docs/content/3.manual/manual.yml
@@ -718,6 +718,16 @@ sections:
input: '[1,2,5,3,5,3,1,3]'
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`
body: |