const alphabet = "abcdefghijklmnopqrstuvwxyz";
const whatever = "aabbccddeeffgghhiijjkklmmnnooppqqrrssttuuvvwwxxyyzz";
const firstNonRepeated1 = str => {
if(!str)
return null;
for(let i = 0; i < str.length; i++)
if(str.indexOf(str[i]) === str.lastIndexOf(str[i]))
return str[i];
return null;
}
const firstNonRepeated2 = str => {
if(!str)
return null;
const freq = {};
for(const char of str)
freq[char] = (freq[char] || 0) + 1;
for(const char of str) {
if(freq[char] === 1)
return char;
}
return null;
};
const firstNonRepeated3 = str => {
const charCount = new Map();
for(let i = 0; i < str.length; i++) {
const char = str[i];
charCount.set(char, (charCount.get(char) || 0) + 1);
}
for(let i = 0; i < str.length; i++) {
const char = str[i];
if(charCount.get(char) === 1)
return char;
}
return null;
};