+ 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"

10th Apr 2017, 3:46 PM
Obongekeme Udo
Obongekeme Udo - avatar
7 Answers
+ 5
I know that the challenge is for JS, but I couldn't resist :) https://code.sololearn.com/cbGC1Bhs09L3/?ref=app
10th Apr 2017, 9:34 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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.
10th Apr 2017, 7:16 PM
Tob
Tob - avatar
+ 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
10th Apr 2017, 5:12 PM
Tob
Tob - avatar
+ 2
Does it work for you now?
10th Apr 2017, 7:32 PM
Tob
Tob - avatar
0
@Tobi your code ain't running, there's a ReferenceError: longestIndex is not defined
10th Apr 2017, 6:35 PM
Obongekeme Udo
Obongekeme Udo - avatar
0
ok... I hope so
10th Apr 2017, 7:52 PM
Obongekeme Udo
Obongekeme Udo - avatar
0
are you good in python's O​OP?
10th Apr 2017, 7:53 PM
Obongekeme Udo
Obongekeme Udo - avatar