[Jprogramming] substring matching between two arrays

Ben Gorte bgorte at gmail.com
Tue Nov 13 00:45:29 UTC 2018


E. is a good start. Since:
 'John' {.@:E. 'Johnny B. Goode'
1
shortNames ({.@:E.)&>/ fullNames
1 1 0 0
0 0 1 0
0 0 0 1
almost gets there. Just needs a finishing touch:
I. |: shortNames ({.@:E.)&>/ fullNames
0
0
1
2
Or if you don't like the transpose and the I. in front:
fullNames I. @: (({.@:E.~)&>/) shortNames
0
0
1
2
and, finally,
match =: I. @: (({.@:E.~)&>/)
fullNames match shortNames
0
0
1
2
Ben
On Tue, Nov 13, 2018 at 11:00 AM Joe Bogner <joebogner at gmail.com> wrote:
> Thanks all. The solutions above were more complicated than I expected. I
> had assumed I was missing something obvious. The obvious miss was to use /
> ... I was thinking I could do something with rank alone
>> For comparison it is combination of map and reduce in javascript
>> ['Joe B','Joe Q','Bobby Z','Janet F'].map(function(x) { return
> ['Joe','Bob','Jane'].reduce(function(acc,y,idx) { return
> x.indexOf(y)>=0?idx:acc },-1) })
>> [0, 0, 1, 2]
>>>> On Mon, Nov 12, 2018 at 6:17 PM 'Mike Day' via Programming <
> programming at jsoftware.com> wrote:
>> > or this variant?
> >
> > f(1 i.~"1+./@E.~&> /)s. NB. f & s obvious?
> > 0 0 1 2
> >
> > This lists the index of the first instance of a substring of each element
> > of fullNames in the
> > shortNames boxed list. It assumes it's there somewhere, but you can use
> > the property
> > that non-inclusion is shown by index = length or number of shortNames.
> >
> > Any help,
> >
> > Mike
> >
> >
> > > On 12 Nov 2018, at 22:29, Brian Schott <schott.brian at gmail.com> wrote:
> > >
> > > Is this anything you can use?
> > >
> > > I.fullNames(((]))&: >"0/-:"1 ((#@]{.[))& >"0/) shortNames
> > >
> > >
> > > --
> > > (B=) <-----my sig
> > > Brian Schott
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > ----------------------------------------------------------------------
> > 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

AltStyle によって変換されたページ (->オリジナル) /