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
1
u/mogzzer4real Jul 27 '19
I tried a for loop but it returns undefined: let freg = 0; let max = 0; let result; for(let count = 0; count < storyWords.length; count++){ if(storyWords[count] === storyWords[count+1]) {
freg++; } else{ freg = 0; }
if(freg>max){
result = freg; max = freg; } } console.log(result);