function differentSymbolsNaive(str) {
// write code here.
let uniqueChars = {};
let uniqueCount = 0;
let chars = str.split('');
//Go through each character in the array
chars.forEach(function (char){
if(uniqueChars[char]){//If it already exists add one to the count, this way we could also
answer the question how many of any character
uniqueChars[char] ++;
}else {// if the character does not exist already, add it to the object and add to our
unique counter we will use to answer this question since we can't easily get a size or
length from the object we are using to store the unique characters themselves, there is
probably a more efficient data structure I could use to get that count for more easily...
uniqueChars[char] = 1;
uniqueCount ++;
}
})
return uniqueCount;
}
/**
* 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);
});
});