[Solved] I need to compare strings in an array and store/return the longest word [duplicate]


Your post isn’t javascript, but here’s basically what you want to do. It should be easy to change it over from javascript.

function compareWords(words){
  var longestWord = '';
  for(var i = 0; i < words.length; i++){
    if(words[i].length > longestWord.length){
      longestWord = words[i];
    }
  }
  return longestWord;
}
var words = ['gunslinger', 'gundam', 'dragon', 'shirt', 'unicorn', 'internationalization'];
compareWords(words);

3

solved I need to compare strings in an array and store/return the longest word [duplicate]