function differentSymbolsNaive(str) {
let splitStr = str.split("")
let unique = splitStr.length //5
for(i=0; i < splitStr.length; i++) {
console.log("unique:" + " " + unique)
console.log(splitStr[i])
console.log("slice:" + " " + splitStr.slice(i+1))
if (splitStr.slice(i+1).includes(splitStr[i])) {
console.log(splitStr.slice(i+1) + " includes " + splitStr[i])
unique = unique - 1
}
}
return unique
}
/* or:
function differentSymbolsNaive(str) {
let splitStr = str.split("")
let diffChar = {}
for(i=0; i < splitStr.length; i++) {
if (diffChar[splitStr[i]] === undefined) {
diffChar[splitStr[i]] = 0
}
diffChar[splitStr[i]]++
}
console.log(diffChar)
return Object.keys(diffChar).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);
});
});