scrimba
Note at 2:24
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:24
AboutCommentsNotes
Note at 2:24
Expand for more info
main.js
run
preview
console
function differentSymbolsNaive(str) {
// write code here
//using SET
return new Set(str).size;

//using OBJECT
if (!str) return 0

const testObject = {}
for (let c of str) {
testObject[c] = (testObject[c] || 0) + 1
}
return Object.keys(testObject).length;

//using ARRAY
if (!str) return 0

const strArray = str.split('')
let newArray = strArray.reduce((newArray, char) => {
if (!(newArray.includes(char))) { newArray.push(char) }
return newArray
},[])
return (newArray && newArray.length) || 0
}

/**
* 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('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = '20201133';

// act
const result = differentSymbolsNaive(str);

// log
console.log("result2: ", result);

// assert
expect(result).toBe(4);
});
});

describe('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = '1 2 3 ';

// act
const result = differentSymbolsNaive(str);

// log
console.log("result3: ", result);

// assert
expect(result).toBe(4);
});
});

describe('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = '"~&~&*&*& 123.12 abc"';

// act
const result = differentSymbolsNaive(str);

// log
console.log("result4: ", result);

// assert
expect(result).toBe(12);
});
});

describe('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = '';

// act
const result = differentSymbolsNaive(str);

// log
console.log("result5: ", result);

// assert
expect(result).toBe(0);
});
});



describe('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = null;

// act
const result = differentSymbolsNaive(str);

// log
console.log("result6: ", result);

// assert
expect(result).toBe(0);
});
});

describe('differentSymbolsNaive()', () => {
it('returns count of unique characters', () => {
// arrange
const str = undefined;

// act
const result = differentSymbolsNaive(str);

// log
console.log("result7: ", result);

// assert
expect(result).toBe(0);
});
});
Console
"result4: "
,
12
,
"result5: "
,
0
,
"result6: "
,
0
,
"result7: "
,
0
,
"result: "
,
3
,
"result2: "
,
4
,
"result3: "
,
4
,
/index.html
LIVE