Create array from string by splitting. You already did that.
Create an empty array that will be used for holding length values of every individual string from previously mentioned string array.
Create loop that goes through string array and pushes length of every individual string into length array.
After loop, sort length array using .sort(). Since sort is only good with string and not with numbers and since length array holds them(lengths of strings are number ofc.), as a parameter to sort() you should use compare function(google it.) in descending order.
My first code was exactly following those steps, except that I stopped in the third one and I got stuck, I didn’t know about the sort() and compare function. So I tried this new algorithm, wich succeeded except for that particular example, and I don’t see any reason why.
because Google is the longest word, your for loop begin the iteration from index 1, so it didn’t find any word long than Google, so it didn’t access the if statement block and ending by returning 23 which is str.length