scrimba
Note at 0:06
Go Pro!Bootcamp

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