Reference · Tiles, layouts and deals
sortSlotsfunction
The slots of a layout, as their numbers, put in order by the keys: ["z", "y", "x"] is layer by layer, row by row,
across (the layout's own order), ["x"] lines them up from the left, ["-z"] has the top of the stacks first. Slots
equal in every key keep their own order, and a key left out is settled last, in the order x, y, z, so the result is
the same whatever the keys.
Import it
import { sortSlots } from "@johnmorrisdotca/jarajara";
Definition
function sortSlots(layout: MahjongLayout, keys?: readonly SlotSortKey[]): number[]
Parameters
| Name | Type | Description |
|---|---|---|
layout | MahjongLayout | The native stacked tile positions. |
keys (optional) | readonly SlotSortKey[] | The native slot axes and sort directions. |
Returns
number[]
The slots of a layout, as their numbers, put in order by the keys: ["z", "y", "x"] is layer by layer, row by row, across (the layout's own order), ["x"] lines them up from the left, ["-z"] has the top of the stacks first. Slots equal in every key keep their own order, and a key left out is settled last, in the order x, y, z, so the result is the same whatever the keys.
Examples
import { layoutFor, sortSlots } from "@johnmorrisdotca/jarajara";
const layout = layoutFor(4)!;
console.log(sortSlots(layout,["z","y","x"]));[
0, 1, 2, 3,
4, 5, 6, 7
]What it prints (run when this page was built)