It's a nice game to write functions in one line. But nothing more...
constareverseString=([firstChar,...str])=>firstChar?areverseString(str)+firstChar:''//duration of 1.000.000 calls = 478 ms constbreverseString=str=>[...str].reverse().join("");//duration of 1.000.000 calls = 1210 ms constcreverseString=str=>[...str].reduce((a,c)=>c.concat(a));//duration of 1.000.000 calls = 943 ms //now the classical way....constreverseString=function(str){letlength=str.lengthletreverse=''for(leti=0;i<length;i++){reverse=str[i]+reverse}returnreverse}//duration of 1.000.000 calls = 210 ms letstart=performance.now()for(lety=1;y<1000000;y++){reverseString('Sauerkrauttopf');}letduration=performance.now()-start;console.log(duration)
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.
the fastest solution in one line:
It's a nice game to write functions in one line. But nothing more...