Skip to content

reverse

ffredyk edited this page Jul 23, 2026 · 1 revision

reverse

Category

Array

Arity

Unaryreverse <array>.

reverse <array>

Description

Reverses the order of elements in the array in-place. The array is modified directly. Returns nil.

How It Works

Calls List<Value>.Reverse() on the underlying list. All elements are reordered. O(n) time, O(1) extra space.

Usage

Basic reverse

_arr = [1, 2, 3, 4];
reverse _arr;                  // _arr is [4, 3, 2, 1]

Reverse iteration

_arr = ["a", "b", "c"];
reverse _arr;
{ systemChat _x } forEach _arr;  // prints "c", "b", "a"

Palindrome check

_isPalindrome = {
    params ["_arr"];
    _copy = +_arr;             // shallow copy
    reverse _copy;
    str _arr == str _copy
};

Undo reverse

reverse _arr;    // first reverse
// ... do work ...
reverse _arr;    // restore original order

Note: Unlike sort, reverse does not take a direction argument — it always reverses.

Thread Safety

Not thread-safe. Array must belong to the current scheduler.

See Also

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally