Created
March 30, 2020 01:34
-
-
Save Nicknyr/7b8640751a797465189de78e76fb45ef to your computer and use it in GitHub Desktop.
CodeSign - Different Symbols Naive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Given a string, find the number of different characters in it. | |
| Example | |
| For s = "cabca", the output should be | |
| differentSymbolsNaive(s) = 3. | |
| There are 3 different characters a, b and c. | |
| */ | |
| function differentSymbolsNaive(s) { | |
| // Turn string into array of strings | |
| let arr = s.split(''); | |
| // Get unique letters by turning the array into a set | |
| let uniqueLetters = new Set(arr); | |
| // Turn the set with unique letters back into an array so we can access the .length attribute of the array | |
| let uniqueLettersArr = [...uniqueLetters]; | |
| // Return the length | |
| return uniqueLettersArr.length; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment