Skip to main content

Standard Library: Collections

Arrays and closed objects are ordinary values. Helpers are global functions, not methods: push(values, 2), not values.push(2).


Arrays​

var values = [1];
push(values, 2);
const last = pop(values);
print(len(values), last, keys({ a: 1 }));
FunctionDescription
len(array)Element count
push(array, value)Append
pop(array)Remove and return the last element
keys(object)Field names of a closed object
unique(array)Deduplicated copy
sort(array)New sorted copy, O(n log n) introsort
bubbleSort(array)In-place educational sort
filter / map / reduce / find / any / allHigher-order helpers

sort uses median-of-three pivoting, an insertion-sort cutoff, and a heapsort fallback so worst-case inputs stay fast.


Queues​

FIFO helpers wrap an array: enqueue at the back, dequeue from the front.

const pending = createQueue();
enqueue(pending, "one");
enqueue(pending, "two");
const first = dequeue(pending);
print(queueIsEmpty(pending), peekQueue(pending), first);
FunctionDescription
createQueue()Empty queue
enqueue(queue, value)Push to the back
dequeue(queue)Pop from the front
peekQueue(queue)Front element without removing
queueIsEmpty(queue)true when empty

Objects / maps​

Closed object literals use string keys:

var config = {
env: "production",
port: 8080
};
print(config["env"]);
config["port"] = 9000;