Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Filtering array on index



23 July 2019, 09:42 Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:

> Turns out the expression can be simpler because the math mode within
> array's index is implicit, so:
>
>   idx=0; olen=$#a+1; a=( ${a[@]/(#m)*/$a[ ++idx % 2 ? olen : idx ]} )
>

The expression can be even simpler if (valid in Zsh, just resolving to
empty element when no ksharrays) index 0 will be used:

idx=0; a=( ${a[@]/(#m)*/$a[ ++idx%2 ? 0 : idx ]} )


Messages sorted by: Reverse Date, Date, Thread, Author