REVERSE

The function REVERSE takes either a List or a string and returns it in reverse order.

This function takes a single piece of input: either a single List, or a single string. It returns a value of the same data type it was given, with the items or characters placed in reverse order.

Declaration

REVERSE(list_of_values) -> reversed
REVERSE(string) -> reversed

Parameters

list_of_values (required, type: List)
Any List.

string (required, type: string)
Any string.

Return Values

reversed (type: List or string)
If a List was given as input, reversed is a List that contains the given List's items in reverse order. If a string was given as input, reversed is a string that contains the given string's characters in reversed order.

Examples

The following example takes the string "abcd" and reverses the characters in it:

REVERSE("abcd") -> "dcba"

Special characters are maintained and reversed by the REVERSE function. In the following example, the capital "T", the space, and the period are all reversed just like any other character:

REVERSE("This string.") -> ".gnirts sihT"

The above examples take strings as input and return them reversed. The following example takes a List of strings and returns a List of the given strings in the reverse order, through the characters in the stings themselves are not reversed. Note that the List given as input includes the string "This string!" from the above example, and yet the REVERSE function does not reverse the characters in it, because it is an item in the given a List:

REVERSE(["This string!", "Another string.", "A third string"]) -> [
  "A third string",
  "Another string.",
  "This string!"
]