Within a sparse-array data-structure how does one retrieve the real position count of such a structure's item?

I have a sparse array of array entries/items as follows …

var indexed = new Array();

indexed["5"] = [35, 2];
indexed["3"] = [20, 2];
indexed["4"] = [25, 3];

I want to find something like the "real" position count of an entry/item within such a sparse array structure by providing an item’s array index( respectively its key).

Expected results:

  • If one does provide 3 (either as string or number value) the returned (index) value should be the number value 0.
  • If one does provide 4 (either as string or number value) the returned (index) value should be the number value 1.
  • If one does provide 5 (either as string or number value) the returned (index) value should be the number value 2.
  • In case of an unsuccessful search the return value should be the number value -1.

95 thoughts on “Within a sparse-array data-structure how does one retrieve the real position count of such a structure's item?”

  1. Right here is the right website for anyone who hopes to find out about
    this topic. You understand so much its almost tough to argue with you (not
    that I really will need to…HaHa). You certainly put a fresh
    spin on a topic that has been written about for decades.
    Wonderful stuff, just great!

    Reply
  2. Hello! This is my 1st comment here so I just wanted to give a
    quick shout out and tell you I genuinely enjoy reading your articles.

    Can you suggest any other blogs/websites/forums that deal with the
    same subjects? Thanks!

    Reply
  3. Right here is the right webpage for everyone who really wants to understand this topic.
    You realize a whole lot its almost hard to argue with you
    (not that I personally would want to…HaHa).

    You certainly put a fresh spin on a topic that has
    been written about for years. Great stuff, just excellent!

    Reply
  4. Do you mind if I quote a few of your articles as long as I provide credit and sources back to your weblog?
    My website is in the exact same niche as yours and my
    visitors would genuinely benefit from a lot of the information you provide here.
    Please let me know if this ok with you. Regards!

    Reply
  5. Hi there, I discovered your website by way of Google at the same
    time as searching for a comparable matter, your site
    got here up, it appears to be like great. I have
    bookmarked it in my google bookmarks.
    Hi there, simply was aware of your blog through Google, and
    located that it is really informative. I am going to watch out for brussels.

    I will be grateful in the event you continue this in future.
    Lots of other folks will be benefited from your writing.

    Cheers!

    Reply
  6. My spouse and I absolutely love your blog and find most of your post’s to be exactly I’m looking for.
    Would you offer guest writers to write content for
    yourself? I wouldn’t mind composing a post or elaborating
    on many of the subjects you write in relation to here. Again, awesome web site!

    Reply
  7. I don’t even understand how I ended up here, however
    I thought this submit used to be good. I don’t know who you might be
    however certainly you are going to a well-known blogger in case you
    aren’t already. Cheers!

    Reply
  8. I blog frequently and I truly thank you for your information.
    Your article has truly peaked my interest. I am going to take a
    note of your blog and keep checking for new information about once per
    week. I opted in for your Feed as well.

    Reply
  9. My spouse and I absolutely love your blog and find the majority of your
    post’s to be what precisely I’m looking for. Would you offer
    guest writers to write content available for
    you? I wouldn’t mind writing a post or elaborating on some
    of the subjects you write related to here. Again, awesome
    weblog!

    Reply
  10. Hey just wanted to give you a quick heads up. The text
    in your content seem to be running off the screen in Chrome.

    I’m not sure if this is a format issue or something to do with
    internet browser compatibility but I figured I’d post to let
    you know. The style and design look great though! Hope you get the problem solved soon. Kudos

    Reply