Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. /**
  2. * @param {string} s
  3. * @return {number}
  4. */
  5. function firstUniqChar(s) {
  6. const arr = Array.from([...s]
  7. .reduce((map, x, i) => map.set(x, !isNaN(map.get(x)) ? null : i) , new Map())
  8. .values());
  9. for(let i = 0; i < arr.length; i++) {
  10. if (arr[i] !== null) { return arr[i]; }
  11. }
  12. return -1;
  13. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement