//convert number to string
if(typeof str === "number") str = str.toString()
let unique = {};
for(let i = 0; i < str.length ; i ++ ){
const letter = str[i];
//checking if the key is in the object and adding 1 if it already has a value
unique[letter] = (unique[letter] || 0 ) + 1
}
console.log(unique)
return Object.entries(unique).length
}
/**
* 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);
});
});
describe('differentSymbolNaive()' , () => {
it('return 0 if pass a empty array' , () => {
const str = []
const result = differentSymbolsNaive(str)
expect(result).toBe(0)
});
});
describe('differentSymbolNaive' , () => {
it('return 0 if pass a empty string', () => {
const str = ''
const result = differentSymbolsNaive(str)
expect(result).toBe(0)
});
});
describe('differentSymbolNaive' , () => {
it('return how many unique number is pass a number ' , () => {
const str = 52135888
const result = differentSymbolsNaive(str)
expect(result).toBe(5)
});
});
function differentSymbolsNaive(str) {
// write code here.
//check for empty array of string
if(str.length === 0) return 0;