Created
April 30, 2021 10:29
-
-
Save leonidkuznetsov18/58d0aefde7a22bc681e6eca213eb46b2 to your computer and use it in GitHub Desktop.
First Unique Character in a String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const firstUniqChar = (s) => { | |
| let res = new Map(); | |
| [...s].forEach((i) => { | |
| res.has(i) ? res.set(i, res.get(i) + 1) : res.set(i, 1) | |
| }) | |
| for (const [key, value] of res.entries()) { | |
| if(value === 1) { | |
| return s.indexOf(key) | |
| } | |
| } | |
| return -1; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment