Basic Tips
-
Use
$ARGS[][]
instead of$ARGS.positional[]
to save 9 bytes -
Use
/
instead ofsplit
-
@sh
instead ofjoin(" ")
(doesn't work on strings) -
add
instead ofjoin("")
(only works on strings) -
[x[]|y]
instead ofx|map(y)
Often you can do basic operators directly, eg.
[x[]+1]
to add one to every element ofx
-
x[]
"unpacks"x
to be parsed into a pipeline or outputted -[1,2,3][]
outputs the elements on separate lines -
%
converts both operands to 64-bit integers. Fo example, you can usex%1e9
instead ofx|floor
if0 ≤ x < 1e9
.
Short indices
operator
Indexing with an array allows finding the indexes of an item or subarray in an array:
[0,5,3,2,6,0][[0]]
> [0, 5]
[0,5,3,2,6,0][[0,5]]
> [0]
Piping this to | length
allows a relatively efficient count of an item in an array.
Undocumented builtins
_nwise(n)
groups an array into chunks of size n. Example:[1,2,3,4,5,6,7,8]|[_nwise(3)]
->[[1,2,3],[4,5,6],[7,8]]