v1
- by nikkypizza 9/16/202000
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
const testCases = [
  {test: 'a',result: 'a'},
  {test: 'abba',result: ''},
  {test: 'sTreSS',result: 'T'},
  {test: "Go hang a salami, I'm a lasagna hog!",result: ','},
  {test: 'moonmen',result: 'e'},
  {test: "hlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7ash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6ihlhlrhlhlrj8e4j8e4apw3tapw3tf7yaf7yaeocrdeocrd21w2k21w2k58jnb58jnbfpnfkfpnfk44wso44wsophfasphfash9e6ih9e6iz", result: 'z'},
  {test: '∞§fi›fl∞§',result: 'fi'}
];

runTests = (cb) => {
  testCases.forEach((item, index) => {
    const result = cb(item.test);
    if (result !== item.result) throw new Error(`Test ${index + 1}: expected ${item.result}, got ${result} instead.`)
  });
}
delete caserun single casemove downdrag and drop case


ready



function firstNonRepeatingLetter(s) {
  var lowerStr = s.toLowerCase();
  var tempSet = new Set(lowerStr.split(''));

  for (let it of tempSet) {
    var firstIndex = lowerStr.indexOf(it);
    var lastIndex = lowerStr.lastIndexOf(it);
  
    if (firstIndex === lastIndex) return s[firstIndex];
  }
  return '';
}

runTests(firstNonRepeatingLetter);
delete caserun single casemove upmove downdrag and drop case


ready



function firstNonRepeatingLetter(str) {
  const lowerCaseStr = str.toLowerCase();
  for (let i = 0; i < str.length; i++) {
    const letter = lowerCaseStr[i];
    if (lowerCaseStr.indexOf(letter) === lowerCaseStr.lastIndexOf(letter)) {
      return str[i];
    }
  }
  return '';
};


runTests(firstNonRepeatingLetter);
delete caserun single casemove upmove downdrag and drop case


ready



const firstNonRepeatingLetter = (string) => {
  const arr = string.toLowerCase().split('');
  let result = arr.find(item => arr.indexOf(item) === arr.lastIndexOf(item)) || '';

  if (result) {
    result = string.includes(result.toUpperCase()) ? result.toUpperCase() : result;
  }

  return result;
};

runTests(firstNonRepeatingLetter);
delete caserun single casemove updrag and drop case


ready



const firstNonRepeatingLetter = (string) => {
  if (!string) {
    return '';
  }

  if (string.length === 1) {
    return string;
  }

  const arr = string.toLowerCase().split('');
  let result = '';

  const tmp = arr.reduce((acc, val) => {
    acc[val] = acc[val] ? acc[val] + 1 : 1;

    return acc;
  }, {});

  for (const [key, val] of Object.entries(tmp)) {
    if (val === 1) {
      result = key;
      break;
    }
  }

  return string.includes(result.toUpperCase()) ? result.toUpperCase() : result;
};

runTests(firstNonRepeatingLetter);
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN