Basic Tips
-
Use $ARGS[][] instead of $ARGS.positional[] to save 9 bytes
-
Use / instead of split
-
@sh instead of join(" ") (doesn't work on strings)
-
add instead of join("") (only works on strings)
-
[x[]|y] instead of x|map(y)
Often you can do basic operators directly, eg. [x[]+1] to add one to every element of x
-
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. For example, you can use x%1e9 instead of x|floor if 0 ≤ 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.