scrimba
Note at 3:29
Go Pro!

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 3:29
AboutCommentsNotes
Note at 3:29
Expand for more info
main.js
run
preview
console
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);
});
});
Console
"result: "
,
3
,
/index.html
LIVE