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.
121
12
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!
@zooeyzooey started
London Fixed Gear and Single-Speed is a community of predominantly fixed gear and single-speed cyclists in and around London, UK.
This site is supported almost exclusively by donations. Please consider donating a small amount regularly.
I think your problem is here:
It's not handling strings with multiple of the same number correctly. E.g.
121
is getting mapped to12
instead of11
.