function differentSymbolsNaive(str) {
if (typeof str !== 'string') {
throw 'input is expected to be a string';
} else if (str.length === 0) {
return 0;
} else if (str.length === 1) {
return 1;
}
const uniqueChars = new Set;
for (char of str) {
uniqueChars.add(char)
}
return uniqueChars.size;
}
/**
* Test Suite
*/
describe('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = 'cabca';
// act
const result = differentSymbolsNaive(str);
// log
console.log("result: ", result);
// assert
expect(result).toBe(3);
});
it('returns count of unique chars for mix of numbers, letters, and symbols', () => {
const str = 'ief8923(*&#ief';
const result = differentSymbolsNaive(str);
expect(result).toEqual(11);
});
it ('returns 0 for an empty string', () => {
const str = '';
const result = differentSymbolsNaive(str);
expect(result).toBe(0);
});
it ('returns 1 for string with single char', () => {
const str = '3';
const result = differentSymbolsNaive(str);
expect(result).toBe(1);
});
it ('throws an error if not passed a string', () => {
const str = 234;
const error = 'input is expected to be a string';
expect(() => differentSymbolsNaive(str)).toThrow(error);
});
});