Tell us what’s happening:
Okay so I have been trying to solve this one for the past 2 hours using different approaches(see the commented out part) but have failed to reach the solution even though I’ve figured the logic. All approaches failed because they need an array to operate upon. I thought first declaring an array as var arr = [ ] and then assigning str1[i].length; to arr would do it but I was wrong. Can someone help me with this?
Your code so far
var arr = [];
var arr1 = [];
function findLongestWord(str) {
str1 = str.split(' ');
for (var i=0; i<str1.length; i++) {
arr += str1[i].length;
}
arr1 = JSON.parse("[" + arr + "]");
// return typeof(arr1);
// return Math.max(...arr);
// arr1.sort(function(a,b) {
// return b - a;
// });
// return Math.max.apply(null, arr);
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
.
Link to the challenge: