Just plugging a buffer into your Fast is twice faster on long strings, same and maybe a little worse on short:
functionfindLongestWordLengthBufferFast(str){constbuf=Buffer.from(str,'ascii')letl=buf.length;letmaxLength=0;letcurrentLength=0;for(leti=0;i<l;++i){if(buf[i]===32){if(currentLength>maxLength){maxLength=currentLength;}currentLength=0;}else{++currentLength;}}// Account for the last wordreturncurrentLength>maxLength?currentLength:maxLength;}
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.
Yeah, it's not listed on the Node docs, because it's inherited.
It's on MDN though.
This is over twice as fast :D
This was 💩 though:
Just plugging a buffer into your
Fast
is twice faster on long strings, same and maybe a little worse on short: