Rules
Create a function that takes a parameter and returns longest word in that parameter
Let's assume that this function will always...
For further actions, you may consider blocking this person and/or reporting abuse
Same thing, but using a reducer instead of sorting.
EDIT: This approach seems to be faster than the sorting one! jsperf.com/longestwordjs/1
This is what I thought to do as well 😄
Good one, didn't think of reduce 👏
Awesome💖
I know one of the tags is 'Javascript' but here is how I would do it in Python:
perl
Go
Can I chime in with a quick C# and LINQ one liner?
Well, the return statement is a one liner :)
Recently started digging my way through GHC libraries
When used according to the specification, this function has O(1) complexity*.
* It doesn't because
split
probably has complexity O(n) or something.It may not be the most eye perfect code however the perf are close to the reducer solution jsperf.com/longestwordjs/11
I would still go to with the reducer solution, but sometimes doing 'old' things works very nice
I also try with for loop / for of, I expected it to be way more faster than everything else but it didn't.
from jsperf.com/foreach-vs-reduce-vs-fo...
Learned something new regarding jsperf, thank you. 🙏
Ignoring punctuation and only considering spaces... ruby solution:
Bro, but what if it's the following sentence:
"I am a 'very('!) long(?) 'sentence'...!!!!""