Expand/Shrink

reverse

Definition: sequence res = reverse(sequence src, sequence from_to={1,-1})
Description: Reverse the order of elements in a sequence.
pwa/p2js: Supported.
Comments: A new sequence is created where the top-level elements appear in reverse order compared to the original sequence.

Optionally the start and end points can be specified, with negative values counting left from the end of the input sequence. See technicalia for compatibility issues with Euphoria.
Examples:
reverse({1,3,5,7})              -- {7,5,3,1}
reverse({{1,2,3}, {4,5,6}})     -- {{4,5,6}, {1,2,3}}
reverse({99})                   -- {99}
reverse("reverse.exw",{3,-6})   -- "resreve.exw"
reverse("reverse.exw",{3,+6})   -- ditto
-- (it is coincidental that -6 and +6 map to the same point in an 11 char string)
reverse("123.456",{-3,-1})      -- "123.654"
--reverse("123.456",5,0)        -- Euphoria equivalent/compilation error
reverse({})                     -- {}
Implementation: See builtins\misc.e (an autoinclude) for details of the actual implementation.
See Also: append, prepend, repeat
Expand/Shrink