# Set vs filter to sort uniques

## Description

are sets a good way to filter out unique values?

## Test runner

Testing in
TestOps/sec
filter naive
``````const longest = (s1, s2) => Array.from(s1+s2).sort().filter((x,i,a) => a.indexOf(x) === i).join('')

let a ='asbavdasfsafa', b='daghjkasfashfjasfsvnx8ewrw';

for(let i = 0; i < 1000; i++) longest(a,b);``````
sort set
``````const longest = (s1, s2) => [...new Set(s1.concat(s2).split(''))].sort((a,b) => a-b)

let a ='asbavdasfsafa', b='daghjkasfashfjasfsvnx8ewrw';

for(let i = 0; i < 1000; i++) longest(a,b);``````
filter hashmap
``````const longest = (s1, s2) => {
const arr = Array.from(s1+s2).sort();
const map = arr.reduce((a,c,i) => { a[c] ||= i;return a } , {});
return arr.filter((x,i) => map[x] === i).join('')
}
let a ='asbavdasfsafa', b='daghjkasfashfjasfsvnx8ewrw';

for(let i = 0; i < 1000; i++) longest(a,b);
``````
filter Object.values
``````const longest = (s1, s2) => {
const arr = Array.from(s1+s2).sort();
const map = arr.reduce((a,c,i) => { a[c] ||= i;return a } , {});
return Object.keys(map).join('')
}
let a ='asbavdasfsafa', b='daghjkasfashfjasfsvnx8ewrw';

for(let i = 0; i < 1000; i++) longest(a,b);
``````