constencodeDuplicate=str=>{//make a frequency mapconstfreqMap=[...str.toLowerCase()].reduce((acc,val)=>{acc[val]=acc[val]+1||1;returnacc;},{});//return the mapped str return[...str.toLowerCase()].map(e=>freqMap[e]==1?'(':')').join('');}
Not that slow :) Better than anything that searched/scanned or did an indexOf for sure! You know I like that || 1 as well, I always do (acc[val] || 0) + 1 - but that is much neater. Borrowing that.
A simple (and somewhat slow) JS solution:
Not that slow :) Better than anything that searched/scanned or did an indexOf for sure! You know I like that || 1 as well, I always do (acc[val] || 0) + 1 - but that is much neater. Borrowing that.
Same to me
|| 0