const firstNonRepeatingCharacter = (str) => { let nonRepeatingCharacter = ''; const repeatingCharacters = {}; for(let char of str) { repeatingCharacters[char] === undefined ? repeatingCharacters[char] = 1 : repeatingCharacters[char] += 1 } for(const [key, value] of Object.entries(repeatingCharacters)) { if (nonRepeatingCharacter !== '') break; if (value === 1) nonRepeatingCharacter = key; } return nonRepeatingCharacter !== '' ? nonRepeatingCharacter : null; };
- const firstNonRepeatingCharacter = (str) => {
console.log("haha");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];}}return null; // return null if no unique character is found- let nonRepeatingCharacter = '';
- const repeatingCharacters = {};
- for(let char of str) {
- repeatingCharacters[char] === undefined ? repeatingCharacters[char] = 1 : repeatingCharacters[char] += 1
- }
- for(const [key, value] of Object.entries(repeatingCharacters)) {
- if (nonRepeatingCharacter !== '') break;
- if (value === 1) nonRepeatingCharacter = key;
- }
- return nonRepeatingCharacter !== '' ? nonRepeatingCharacter : null;
- };