scrimba
Note at 0:07
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:07
AboutCommentsNotes
Note at 0:07
Expand for more info
main.js
run
preview
console
// import uniq from "lodash/uniq"

function differentSymbolsNaive(str) {
let unique = [];
str.split('').map(c => {
if (!unique.includes(c)) {
unique.push(c);
}
})

return unique.length;
}

function differentSymbolsSet(str) {
let s = new Set(str.split(''));

return s.size;
}

function differentSymbolsLodash(str) {
return _.uniq(str.split('')).length
}

/**
* Test Suite
*/
function testDifferentSymbols(fn) {
describe(`${fn.name}()`, () => {
it('returns count of unique characters', () => {
// arrange
const str = 'cabca';

// act
const result = fn(str);

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

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

let differentSymbols = [
differentSymbolsNaive,
differentSymbolsSet,
differentSymbolsLodash
]
for (fn of differentSymbols) {
testDifferentSymbols(fn);
}
Console
"result: "
,
3
,
"result: "
,
3
,
"result: "
,
3
,
/index.html
LIVE