+ 2
Code challenge 2(in JavaScript)
Write a function called longest which will take a string of space-separated words and will return the longest one. For example: longest ("This is fun") => "This"
7 Answers
+ 5
I know that the challenge is for JS, but I couldn't resist :)
https://code.sololearn.com/cbGC1Bhs09L3/?ref=app
+ 3
Code runs fine for me. When I made it, I got an error after adding some whitespace (which should not have changed anything) though, so perhaps the playground has some issues here.
Maybe try again. If it still does not work try on another device or remove line breaks. If you can pin down the problem, this would make for a good bug report.
+ 2
Not a perfect solution, as it counts punctuation marks to the word length. A possible fix would be to use the string replace method or some hacky regex.
The trick here was to use reduce to build an "argmax" like expression.
https://code.sololearn.com/WFoV9erpryQt/?ref=app
+ 2
Does it work for you now?
0
@Tobi your code ain't running, there's a ReferenceError: longestIndex is not defined
0
ok... I hope so
0
are you good in python's OâOP?



