function differentSymbolsNaive(str) {
// 1. For loop
var unique= "";
for(var i = 0; i < str.length; i++)
{
if(unique.indexOf(str.charAt(i)) < 0)
{
unique += str.charAt(i);
}
}
//return unique.length;
//2. Using set...
var stringResult = String.prototype.concat(...new Set(str)).length
//3. Arrays
var arrayresult = str.split('').filter(function(item, i, ar){ return ar.indexOf(item) === i; })
.join('').length;
// 4. loadash
// return _.uniq(str).join('').length; // gives 'abc'
//5. Array prototype...
var arrayprotoResult = Array.prototype.map.call(str,
(obj,i)=>{
if(str.indexOf(obj,i+1)==-1 ){
return obj;
}
}
).join("").length;
//6. While loop
var len = str.length;
var coll = [];
var a=0;
while(len--)
{
if(!coll.includes(str[len]))
{
coll.push(str[len]);
}
}
return coll.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);
});
});