scrimba
Note at 2:46
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 2:46
AboutCommentsNotes
Note at 2:46
Expand for more info
main.js
run
preview
console
function differentSymbolsNaive(str) {
// write code here.
//check for empty array of string
if(str.length === 0) return 0;
//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)
});
});
Console
{c:
2
, a:
2
, b:
1
}
,
"result: "
,
3
,
{1:
1
, 2:
1
, 3:
1
, 5:
2
, 8:
3
}
,
/index.html
LIVE