JavaScript/5kyu/First_non_repeating_character.js
// If a string contains all repeating characters, it should return an empty string ("") or None -- see sample tests.
If a string contains all repeating characters, it should return an empty string ("") or None -- see sample tests.
If a string contains all repeating characters it should return an empty string ( " " ) or None -- see sample tests .
function firstNonRepeatingLetter(s) {
  counter = {}
  arr = s.toLowerCase().split('');
  if (arr.length === 1) return s;
  if (s == '' || arr.sort().every((val,i,arr)=>val===arr[0])) return '';
  arr.map(val=> counter[val] = (counter[val] || 0) + 1);
  for (let key in counter) {
    if (counter[key] > 1) {
      delete counter[key];
    }
  }
  return Object.keys(counter).length !== 0 ? s.split('').find(a=>counter.hasOwnProperty(a.toLowerCase())) : '';
}
function firstNonRepeatingLetter ( s ) { counter = { } arr = s . toLowerCase ( ) . split ( '' ) ; if ( arr . length === 1 ) return s ; if ( s == '' || arr . sort ( ) . every ( ( val , i , arr ) => val === arr [ 0 ] ) ) return '' ; arr . map ( val => counter [ val ] = ( counter [ val ] || 0 ) + 1 ) ; for ( let key in counter ) { if ( counter [ key ] > 1 ) { delete counter [ key ] ; } } return Object . keys ( counter ) . length !== 0 ? s . split ( '' ) . find ( a => counter . hasOwnProperty ( a . toLowerCase ( ) ) ) : '' ; }
If a string contains all repeating characters, it should return an empty string ("") or None -- see sample tests.
If a string contains all repeating characters it should return an empty string ( " " ) or None -- see sample tests .