r/programmingchallenges • u/mogzzer4real • Jul 27 '19
An Javascript array challenge
Im having struggles with the problems on codecademy's project: Minilinter The problem is: Given an array of strings, find the word that appears the greatest number of times
0
Upvotes
View all comments
Show parent comment
2
u/fresnik Jul 27 '19
Here you are comparing one word in the array with the next one in the array, and if they are they same, then you increase the count. This would only work if the array is sorted. If it is, then it's a fine solution.
Your problem here however is that you go past the end of the array. The for loop goes up to storyWords.length - 1 (the last index of the array), but then you are trying to access storyWords[count+1], which is one after the end of the array. Try changing the for loop to stop at the next-to-last element.