Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Finding index of an entry in an Array

by jrsimmon (Hermit)
on Dec 07, 2007 at 03:52 UTC ( #655578=note: print w/replies, xml ) Need Help??


in reply to Re: Finding index of an entry in an Array
in thread Finding index of an entry in an Array

note that if there are duplicate entries in the array, the index of the first (lowest index) entry will be returned. eliminate the reverse call to have it the other way.
This should be restated to say exactly two duplicate entries. A third or further duplicates would be undetectable with this method.
  • Comment on Re^2: Finding index of an entry in an Array

Replies are listed 'Best First'.
Re^3: Finding index of an entry in an Array
by Anonymous Monk on Dec 07, 2007 at 08:16 UTC
    i don't understand your point. i would not say my approach was able to directly detect any number of duplicates, whether 2, 3 or more. (the only, and somewhat awkward, way to detect the presence of duplicates with this specific caching approach would be to build two caches, one based on ascending indices, the other based on descending indices, and compare the two indices derived from the two caches. if they are not the same, two or more duplicates must exist. however, i can think of better ways to handle this sort of info.)

    the point i was trying, perhaps clumsily, to make in my original post was that my method, in common with all the other approaches that had appeared by then, would, due to the use of reverse, return the first (i.e., lowest) index of a match in the case of duplicates, but that a variation could easily be had that would return the last/highest index.

    since my original post, i see that some solutions have been posted that return the indices of all matches, which i did not understand to be a requirement of the original question. oh, well...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://655578]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-10-19 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (255 votes). Check out past polls.

    Notices?