Top N
FreeLogic@rabbinatix/top-n by Rabbinatixupdated Oct 4, 2026
The N items with the highest `score`.
Sort by an item path (score), descending, then Slice keeps the first N. Asking for more than there are is fine.
Shows: Sort by a path, Slice.
How to use it
Add it to your logic, then add a Call Function step in any logic and pick Top N. It belongs to no system, so every system can use it. Or download the TypeScript and call it from your own code.
Inputs
items: List of records
n: Whole number
Outputs
top: List of records
Previewdrag the steps around; scroll to zoom
Function Entry, Input / output. 0 inputs, 3 outputs. step 1 of 4
Top N
items
n
Sort, Collection. 1 input, 1 output. step 2 of 4
Sort
array
result
Slice, Collection. 3 inputs, 1 output. step 3 of 4
Slice
array
start
end
result
Return, Input / output. 2 inputs, 0 outputs. step 4 of 4
Return
top
Arrow keys: next or previous step in flow order. Alt with arrows: nearest step in that direction. Enter: open. Shift F10: more actions.
Examplesrun live against the logic · 2/2 pass
| Passed | Example | Input | Output |
|---|---|---|---|
| Top 2 | {"items":[{"name":"Ann","score":7},{"name":"Bo","score":9},{"name":"Cy","score":8}],"n":2} | {"top":[{"name":"Bo","score":9},{"name":"Cy","score":8}]} | |
| More than there are | {"items":[{"name":"Ann","score":7}],"n":3} | {"top":[{"name":"Ann","score":7}]} |
Try it
Versions
In this package
Top N (entry)
