[Jprogramming] locating indices of string in list of strings
robert therriault
bobtherriault at mac.com
Sun Aug 31 00:21:29 UTC 2014
Whoops,
Don, for some reason I got it into my head that you wanted to keep the first zero. Nub would work against you in that case as it would hold on to the first zero and remove the rest.
You could always just remove the 0 using Less (-.) in this case the Passive version (-.~)
0-.~ ( i.#arr) * +./"1 'cd' E."1 arr
1 3 5 7 9
Cheers, bob
On Aug 30, 2014, at 4:50 PM, robert therriault <bobtherriault at mac.com> wrote:
> Hi Don,
>
> I think that copy (#) combined with increment (>:) may be able to do the trick.
>
> 1 1 0 0 1#i.5 NB.index 0
> 0 1 4
> 1 1 0 0 1>:@#i.5 NB.index 1
> 1 2 5
>
> Although reading through your journey to get to this point I wonder if Nub (~.) would do the trick.
>
> arr
> ab
> cd
> yyy
> jcd
> ab
> cd
> yyy
> jcd
> ab
> cd
> +./"1 'cd' E."1 arr
> 0 1 0 1 0 1 0 1 0 1
> ( i.#arr) * +./"1 'cd' E."1 arr
> 0 1 0 3 0 5 0 7 0 9
> ~. ( i.#arr) * +./"1 'cd' E."1 arr
> 0 1 3 5 7 9
>
> Cheers, bob
>
> On Aug 30, 2014, at 4:30 PM, Don Kelly <dhky at shaw.ca> wrote:
>
>> 1 1 0 0 1/⍳5
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list