]> granicus.if.org Git - jq/commitdiff
Reverse function. Closes #94.
authorStephen Dolan <mu@netsoc.tcd.ie>
Thu, 16 May 2013 13:25:28 +0000 (14:25 +0100)
committerStephen Dolan <mu@netsoc.tcd.ie>
Thu, 16 May 2013 13:25:28 +0000 (14:25 +0100)
builtin.c
docs/content/3.manual/manual.yml

index 47c13865101b7c96a09762cd93e1b64f5b54912d..48d711090edd194430ad3e7663eb849efcd94711 100644 (file)
--- 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)]];",
 };
 
 
index e5fff391c0cd3dbfe828662fb1620371c98c00ab..7038b5fc37a53a36fe98b31aa48859b54cbdd175 100644 (file)
@@ -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: |