Basic Tips
-
Use
$ARGS[][]instead of$ARGS.positional[]to save 9 bytes -
Use
/instead ofsplit -
@shinstead ofjoin(" ")(doesn't work on strings) -
addinstead 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"xto be parsed into a pipeline or outputted -[1,2,3][]outputs the elements on separate lines -
%converts both operands to 64-bit integers. For example, you can usex%1e9instead ofx|floorif0 ≤ 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.