Skip to content

Instantly share code, notes, and snippets.

@leonidkuznetsov18
Created April 30, 2021 10:29
Show Gist options
  • Select an option

  • Save leonidkuznetsov18/58d0aefde7a22bc681e6eca213eb46b2 to your computer and use it in GitHub Desktop.

Select an option

Save leonidkuznetsov18/58d0aefde7a22bc681e6eca213eb46b2 to your computer and use it in GitHub Desktop.
First Unique Character in a String
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