Reverse

Copied!
( source )

Description

The Reverse function returns in reverse order the items in source, which can be an Array, a Set, or a Page.

Parameters

Parameter Type Definition and Requirements

source

Array, Set, or Page

The array, set, or page whose items should be reversed.

Returns

When source is an Array, an Array containing the items found in source, with their original order reversed.

When source is a Set, a Set containing the items found in source, with their original order reversed.

When source is a Page, a Page of the items found in source, with their original order reversed.

Examples

  1. The following query passes an array to Reverse:

    Copied!
    (['a', 'b', 'c', 1, 2, 3])
    [ 3, 2, 1, 'c', 'b', 'a' ]
    Query metrics:
    •    bytesIn:  31

    •   bytesOut:  32

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 1ms

    •    retries:   0

  2. The following query reverses the set of documents in the Letters collection (established in the Indexing tutorial, and then paginates the set:

    Copied!
    (((('Letters'))))
    {
      data: [
        (("Letters"), "126"),
        (("Letters"), "125"),
        (("Letters"), "124"),
        (("Letters"), "123"),
        (("Letters"), "122"),
        (("Letters"), "121"),
        (("Letters"), "120"),
        (("Letters"), "119"),
        (("Letters"), "118"),
        (("Letters"), "117"),
        (("Letters"), "116"),
        (("Letters"), "115"),
        (("Letters"), "114"),
        (("Letters"), "113"),
        (("Letters"), "112"),
        (("Letters"), "111"),
        (("Letters"), "110"),
        (("Letters"), "109"),
        (("Letters"), "108"),
        (("Letters"), "107"),
        (("Letters"), "106"),
        (("Letters"), "105"),
        (("Letters"), "104"),
        (("Letters"), "103"),
        (("Letters"), "102"),
        (("Letters"), "101")
      ]
    }
    Query metrics:
    •    bytesIn:    63

    •   bytesOut: 2,727

    • computeOps:     1

    •    readOps:     8

    •   writeOps:     0

    •  readBytes: 1,300

    • writeBytes:     0

    •  queryTime:  13ms

    •    retries:     0

  3. The following query reverses the page of results from paginating the documents in the Letters collection:

    Copied!
    (
      (
        (('Letters')),
        { size: 3, after: (('Letters'), '104') }
      )
    )
    {
      before: [ (("Letters"), "104") ],
      after: [ (("Letters"), "107") ],
      data: [
        (("Letters"), "106"),
        (("Letters"), "105"),
        (("Letters"), "104")
      ]
    }
    Query metrics:
    •    bytesIn:   124

    •   bytesOut:   564

    • computeOps:     1

    •    readOps:     8

    •   writeOps:     0

    •  readBytes: 1,174

    • writeBytes:     0

    •  queryTime:  14ms

    •    retries:     0

    Notice that Reverse has reversed the order of the results in the page, but has not affected the pagination order.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!