const firstNonRepeatingCharacter = (str) => { const charCount = {}; for (const char of str) { charCount[char] = (charCount[char] || 0) + 1; } for (const char of str) { if (charCount[char] === 1) { return char; } } return null; };
- const firstNonRepeatingCharacter = (str) => {
for (let i = 0; i < str.length; i++) {let seenDuplicate = false;for (let j = 0; j < str.length; j++) {if (str[i] === str[j] && i !== j) {seenDuplicate = true;break;}}if (!seenDuplicate) {return str[i];- const charCount = {};
- for (const char of str) {
- charCount[char] = (charCount[char] || 0) + 1;
- }
- for (const char of str) {
- if (charCount[char] === 1) {
- return char;
- }
- }
return null; // return null if no unique character is found- return null;
- };