Can someone help and review my solution for the algorithm? :

function findLongestWord(str) {

var compare = [];

var poop = str.split(" ");

for(var i=0; i < poop.length; i++){

compare.push(poop[i].length);

}

return Math.max.apply(null, compare);

}

findLongestWord(“The quick brown fox jumped over the lazy dog”);

*I got the Math.max.apply(null, x) from MDN.

I googled other people’s solutions and it seemed like my way of solving it was not efficient. Let me know what you think!