You are reading a single comment by @zooeyzooey and its replies. Click here to read the full conversation.
  • I think your problem is here:

    Object.keys(strNumMap).reduce((res, key) => {
      const index = str.indexOf(key);
      if (index > -1) {
        res[key] = index;
      }
      return res;
    }
    

    It's not handling strings with multiple of the same number correctly. E.g. 121 is getting mapped to 12 instead of 11.

  • Yep, that was it. Refactored to get arr of all indexes rather than just the first and got the right answer. Thank you!

    Would have been nice to have an example in the test data with that structure, but oh well!

About

Avatar for zooeyzooey @zooeyzooey started