Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created March 30, 2020 01:34
Show Gist options
  • Select an option

  • Save Nicknyr/7b8640751a797465189de78e76fb45ef to your computer and use it in GitHub Desktop.

Select an option

Save Nicknyr/7b8640751a797465189de78e76fb45ef to your computer and use it in GitHub Desktop.
CodeSign - Different Symbols Naive
/*
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