Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://655578]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2018-09-25 13:30 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (199 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!