JSFiddle - React, Tailwind, and code Playground

by Jessie Lau

HTML

<!-- Using the JavaScript language, have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty. -->

JavaScript

function LongestWord(sen) { 
  var ponctuations = [",",".","!","?",";",":"]; 
    var res;
    for(k = 0; k < ponctuations.length; k++){
        res += sen.replace(ponctuations[k]," ");
        console.log(res);
        }
   var words = res.split("");
  var longest = "";
  for(i = 0; i < words.length; i++){
      if(words[i].length > longest.length){
      longest = words[i];
      }

  }
  return longest;       
}

var s = LongestWord("ok,ddd.");
//console.log(s);