Write a function named first_non_repeating_letter that takes a string input, and returns the first character that is not repeated anywhere in the string.
For example, if given the input 'stress', the function should return 't', since the letter t only occurs once in the string, and occurs first in the string.
As an added challenge, upper- and lowercase letters are considered the same character, but the function should return the correct case for the initial letter. For example, the input 'sTreSS' should return 'T'.
If a string contains all repeating characters, it should return an empty string ("") or None – see sample tests.
Ruby
Init
1 2 3
deftongues(code) #your code here end
Sample Testing
1 2 3 4 5 6 7 8 9 10
Test.describe('Simple Tests') do it('should handle simple tests') do Test.assert_equals(first_non_repeating_letter('a'), 'a') Test.assert_equals(first_non_repeating_letter('stress'), 't') Test.assert_equals(first_non_repeating_letter('moonmen'), 'e') end it('should handle empty strings') do Test.assert_equals(first_non_repeating_letter(''), '') end end
Javascript
Init
1 2 3
functionfirstNonRepeatingLetter(s) { // Add your code here }