can't beat this can ya 😏
const firstNonRepeatingCharacter = (str) => { let chars = [], counts = []; for(char of str) { let index = chars.indexOf(char); if(index < 0) { index = counts.length; chars.push(char); counts.push(0); } counts[index]++; } for(let i = 0; i < chars.length; i++) { if(counts[i] === 1) { return chars[i]; } } return null };
- const firstNonRepeatingCharacter = (str) => {
- let chars = [], counts = [];
for(const char of str) {- for(char of str) {
- let index = chars.indexOf(char);
- if(index < 0) {
- index = counts.length;
- chars.push(char);
- counts.push(0);
- }
- counts[index]++;
- }
for(let index = 0; index < chars.length; index++) {if(counts[index] === 1) {return chars[index];- for(let i = 0; i < chars.length; i++) {
- if(counts[i] === 1) {
- return chars[i];
- }
- }
return null;- return null
- };