Ad
Code
Diff
  • const firstNonRepeatingCharacter = (str) => {
      return [...str].find((v) => str.indexOf(v) === str.lastIndexOf(v)) || 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
    • return [...str].find((v) => str.indexOf(v) === str.lastIndexOf(v)) || null;
    • };