I did a robustness-test and a perf-test and made some adjustments...
/*
@func
get the uniq list of dups in arr
@notes
also applies to empty strs
filters out nils
@param {string[]|number[]} a - of prims, i.e. strings or numbers
@return {string[]|number[]} uniq list of dups from orig arr
*/constfindDups=a=>{lethash={};// hash table of seen valsletdupes=[];//finalfor(leti=0;i<a.length;i++){// now go through the arr onceif(isNil(a[i])){continue;}if(hash[a[i]]){dupes.push(a[i])// already seen, so add to dupes}else{hash[a[i]]=true;// first time seen, add it to hash of seen vals}}returndupes;};//@testsconsta=[[1,2,3,2,3],[1,2,3],[0,0,3],[0,0,3,-1,-1],[],["one","two","Two"],["one","two","two"],["","","two"],[null,undefined,"two"],[null,undefined,null,undefined,"two"],];logForeachParam(findDups,a);/*
@output
[ 2, 3 ]
[]
[ 0 ]
[ 0, -1 ]
[]
[]
[ 'two' ]
[ '' ]
[]
[]
*///@perftesttimeInLoop("findDups",1e6,()=>findDups([1,2,3,2,3]));/*
@output
findDups: 1e+6: 993.192ms - without toString()
findDups: 1e+6: 1.618s - with toString()
*/
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice work Andrew.
I did a robustness-test and a perf-test and made some adjustments...