AlgoDaily 14: Find First Non-Repeating Character
https://algodaily.com/challenges/find-first-non-repeating-character
This shouldn’t be too hard with a hash map of characters to counts, relying on JavaScript objects having ordered keys to then find the first character with a single occurrence.
function firstNonRepeat(str) {
const counts = {}
for (let char of str) {
counts[char] = counts[char] ? counts[char] + 1 : 1;
}
for (let char in counts) {
if (counts[char] === 1) {
return char;
}
}
return "";
}