Different Symbols Naive

Description


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.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] string s

A string of lowercase English letters.

Guaranteed constraints: 3 ≤ s.length ≤ 1000.

  • [output] integer

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
function differentSymbolsNaive(s) {
    return s.split('').filter((el,i,self)=>i===self.indexOf(el)).length
}