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

Re: Filtering array on index



On Thu, 25 Oct 2018 at 13:30, Jesper Nygårds <jesper.nygards@xxxxxxxxx> wrote:
>
> I have an array which is the result of using zparseopts on a specification
> that makes it possible to specify several filters with a -v flag. The
> resulting array might look like the following:
>
> myarr=(-v filter1 -v filter2)

I've recently had this problem. One other way to do it:

~ idx=0; olen=$#a+1; a=( ${a[@]/(#m)*/$a[$(( ++idx % 2 ? olen : idx ))]} )
~ print -rl -- $a
filter1
filter2

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



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