Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ declare class StaticArray<T> {
lastIndexOf(searchElement: T, fromIndex?: i32): i32;
concat(items: Array<T>): Array<T>;
slice(from: i32, to?: i32): Array<T>;
sort(comparator?: (a: T, b: T) => i32): this;
join(separator?: string): string;
toString(): string;
}
Expand Down
6 changes: 6 additions & 0 deletions std/assembly/staticarray.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="./rt/index.d.ts" />

import { OBJECT, BLOCK_MAXSIZE, TOTAL_OVERHEAD } from "./rt/common";
import { COMPARATOR, SORT } from "./util/sort";
import { idof } from "./builtins";
import { Array } from "./array";
import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_HOLEYARRAY } from "./util/error";
Expand Down Expand Up @@ -229,6 +230,11 @@ export class StaticArray<T> {
return slice;
}

sort(comparator: (a: T, b: T) => i32 = COMPARATOR<T>()): this {
SORT<T>(changetype<usize>(this), this.length, comparator);
return this;
}

join(separator: string = ","): string {
if (isBoolean<T>()) return joinBooleanArray(changetype<usize>(this), this.length, separator);
if (isInteger<T>()) return joinIntegerArray<T>(changetype<usize>(this), this.length, separator);
Expand Down
Loading