New answers tagged

2

Josiah's answer covers most stuff pretty well. The only additional suggestion I have is an alternative to a switch statement: a lookup table of actions. Something like: const query_types = { 1: (x)=>{ frequencyArray[arr[1]] = (frequencyArray[arr[1]] || 0) + 1; }, 2: (y)=>{ ... }, 3: (z)=>{ ... } }; for(let i=0 ;...


4

There's a few general code hygiene things that I'll look at first, and then I'll comment on the algorithm design. First, const should mean constant. I know that in Javascript you don't get in trouble for changing the contents of a const array but it's still confusing to use it with a variable whose job is to change. const arr I like but const resultArray I ...


2

Another simple solution would be base conversion. The original string contains the characters 0 to 5, meaning it is in base 6. Every pair of characters can therefore be encoded as one base 36 character. The resulting string will contain the characters a to z and 0 to 9. A string of length n will, after conversion, have length n/2 if n is even, or (n/2) + 1 ...


Top 50 recent answers are included