Tail of a list

Keep N items from the end of a list. Default is the last 5. Four Pick modes: Last (default, positional tail), Random (unbiased sample), Longest (by character count, ties broken by input order), Shortest (by character count).

Input
Ready
Output
Live

Keep N from the end, by position or by shape

Last mode (default) slices the final N items preserving order - `Array.slice(Math.max(0, length - n))`. If the list has fewer than N items, every item is kept. Random picks N items via a Fisher-Yates shuffle of a copy of the list, then slices the first N - unbiased, not positional.

Longest / Shortest sort the list by character count (descending / ascending) and take the first N. Character count is `String.length` on each trimmed-on-input line - multi-byte characters count as their UTF-16 code-unit length (emoji and supplementary-plane characters count as 2).

Sorting is stable (ES2019+), so ties preserve original input order. `N` greater than the list length is clamped to the list length. Pair with Head of a list for the other end - same three non-positional modes, opposite positional default.

How to use tail of a list

  1. 1Paste your list into the input panel
  2. 2Set `Keep N` to the number of items you want (default `5`)
  3. 3Pick mode: Last (default positional), Random, Longest, or Shortest
  4. 4Output updates live; `N` past the list length keeps everything
  5. 5For the first-N side, use Head of a list

Keyboard shortcuts

Drive ListShift without touching the mouse.

Shortcut Action
Ctrl ZUndo last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor
EscExit fullscreen
Ctrl KOpen the command palette to jump to any tool
Ctrl SSave current pipeline draft Plus
Ctrl PRun a saved pipeline Plus

What this tool actually does

Four ways to pick N items from a list.

Last mode (default): positional tail

`Array.slice(length - n)` gives the last N items in their original order. The common case when "tail" means "recent" in a log or chronological list.

Random mode: unbiased sample of N

Fisher-Yates shuffles a copy of the list, then takes the first N. Each item has equal probability of being selected; no item repeats. Re-run gives different results (no seed).

Longest mode: N items with most characters

Sorts by `String.length` descending and takes the top N. Ties preserve input order (stable sort). Useful for surfacing verbose lines, long URLs, or detailed entries.

Shortest mode: N items with fewest characters

Sort ascending by length, take top N. Useful for IDs vs descriptions, or for finding empty-looking entries.

N clamped to list length

If your list has 10 items and `Keep N: 50`, you get all 10 - no padding, no error. If the list is empty, the output is empty too.

Worked example

Defaults `Keep N: 5, Pick: Last` on a 6-item list → the final 5 items in order.

Input
apple
orange
banana
grape
melon
berry
Output
orange
banana
grape
melon
berry

Settings reference

How each option shapes the output using the sample above.

Setting What it does Effect on the sample
`Keep N: 5, Pick: Last` (defaults) Last 5 items, original order `orange, banana, grape, melon, berry`
`Keep N: 3, Pick: Last` Last 3 items `grape, melon, berry`
`Keep N: 3, Pick: Random` Unbiased random sample of 3 items Different 3 items each run (no seed)
`Keep N: 2, Pick: Longest` 2 items with most characters `orange`, `banana` (both 6 chars, ties preserve order)
`Keep N: 2, Pick: Shortest` 2 items with fewest characters `apple`, `grape` (both 5 chars)

FAQ

What happens if the list has fewer than N items?
Every item is kept. No padding, no error - the output simply has fewer than N items. If your list has 3 items and `Keep N: 10`, the output is the same 3 items.
Is Random mode reproducible?
No - there is no seed input. Each run uses fresh `Math.random()` calls, so the same input produces a different random sample every time. For reproducible sampling, take the output of one run and work with it directly.
How are ties broken in Longest / Shortest?
By original input order (stable sort). Two items with the same character count appear in the order they appeared in the input.
How is this different from Truncate?
Truncate keeps the first N items (same as Head mode `first`). Tail keeps the last N (Last mode), or N picked by shape / random. Pick this tool when "end of the list" or "N-by-shape" is the intent.
Does mode Last count blank lines?
Yes - every line counts, blank or not. The op uses `splitLines(input)` and does not filter blanks. Run Remove empty lines first if you want blanks excluded from the tail count.