[Jprogramming] Removing n occurences
June Kim (김창준)
juneaftn at gmail.com
Wed Sep 12 05:49:59 UTC 2012
Hi Roger,
Thanks, Roger, as always. I am aware of that wiki page, but I think it's a
more general approach. How could I use that to make removen simpler and
more elegant?
Best regards
June
On Tue, Sep 11, 2012 at 3:42 PM, Roger Hui <rogerhui.canada at gmail.com>wrote:
> You may want to look at
> http://www.jsoftware.com/jwiki/Essays/Progressive%20Index-Of
>
>
>
> On Mon, Sep 10, 2012 at 11:37 PM, June Kim (김창준) <juneaftn at gmail.com>
> wrote:
>
> > Hello
> >
> > If you want to remove all occurences of x in y, it's simple in J:
> >
> > y-.x
> >
> > For example,
> >
> > 1 2 3 1 9 10 8 1 -. 1
> > 2 3 9 10 8
> >
> > Now, if you want to remove n occurences of x in y, how would you do that?
> >
> > Following is my quick and dirty solution:
> >
> > removen=.13 : 'y#~-.((x>:]) *. 0&~:) (*+/\) (={.)y'
> > 3 removen 'fasdffgh flkjffif'
> > asdgh flkjffif
> > 3 removen 1 1 2 3 1 9 10 8 1
> > 2 3 9 10 8 1
> >
> > I used the first item in y as the "item to remove" -- smiliar to the cut
> > verb.
> >
> > I believe there are simpler solutions as always(you may relax the
> constrain
> > for keeping the order of y). Any suggestions?
> >
> > June
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list