scrimba
Note at 0:31
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:31
AboutCommentsNotes
Note at 0:31
Expand for more info
main.js
run
preview
console
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);
});
});
Console
"unique: 5"
,
"c"
,
"slice: a,b,c,a"
,
"a,b,c,a includes c"
,
"unique: 4"
,
"a"
,
"slice: b,c,a"
,
"b,c,a includes a"
,
"unique: 3"
,
"b"
,
"slice: c,a"
,
"unique: 3"
,
"c"
,
"slice: a"
,
"unique: 3"
,
"a"
,
"slice: "
,
"result: "
,
3
,
/index.html
LIVE