API / Belt / SortArray

You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest API docs here.

(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)

SortArray

SortArrayInt

RE
module Int : Belt_SortArrayInt

Specalized when key type is int, more efficient than the generic type

SortArrayString

RE
module String: Belt_SortArrayString

Specalized when key type is string, more efficient than the generic type

strictlySortedLengthU

RE
let strictlySortedLengthU: (array('a), [@bs] (('a, 'a) => bool)) => int;

strictlySortedLength

RE
let strictlySortedLength: (array('a), ('a, 'a) => bool) => int;

strictlySortedLenght(xs, cmp); return +n means increasing order -n means negative order

RE
Belt.SortArray.strictlySortedLength([|1, 2, 3, 4, 3|], (x, y) => x < y) == 4; Belt.SortArray.strictlySortedLength([||], (x, y) => x < y) == 0; Belt.SortArray.strictlySortedLength([|1|], (x, y) => x < y) == 1; Belt.SortArray.strictlySortedLength([|4, 3, 2, 1|], (x, y) => x < y) == (-4);

isSortedU

RE
let isSortedU: (array('a), [@bs] (('a, 'a) => int)) => bool;

isSorted

RE
let isSorted: (array('a), ('a, 'a) => int) => bool;

isSorted(arr, cmp): Returns true if array is increasingly sorted (equal is okay)

stableSortInPlaceByU

RE
let stableSortInPlaceByU: (array('a), [@bs] (('a, 'a) => int)) => unit;

stableSortInPlaceBy

RE
let stableSortInPlaceBy: (array('a), ('a, 'a) => int) => unit;

stableSortByU

RE
let stableSortByU: (array('a), [@bs] (('a, 'a) => int)) => array('a);

stableSortBy

RE
let stableSortBy: (array('a), ('a, 'a) => int) => array('a);

stableSortBy(xs, cmp): Returns a fresh array Sort xs in place using comparator cmp, the stable means if the elements are equal, their order will be preserved

binarySearchByU

RE
let binarySearchByU: (array('a), 'a, [@bs] (('a, 'a) => int)) => int;

binarySearchBy

RE
let binarySearchBy: (array('a), 'a, ('a, 'a) => int) => int;

If value is not found and value is less than one or more elements in array, the negative number returned is the bitwise complement of the index of the first element that is larger than value.

If value is not found and value is greater than all elements in array, the negative number returned is the bitwise complement of (the index of the last element plus 1)for example, if key is smaller than all elements return -1 since lnot(-1) == 0 if key is larger than all elements return lnot(-1) == 0 since lnot(- (len + 1)) == len

RE
Belt.SortArray.binarySearchBy([|1, 2, 3, 4, 33, 35, 36|], 33, Pervasives.compare) == 4; lnot(Belt.SortArray.binarySearchBy([|1, 3, 5, 7|], 4, Pervasives.compare)) == 2;