用JS写 输入一段英语找出最长的英语单词
方法一
let read =require("readline-sync");console.log("输入英语语句");let str=read.question("");console.log("最长的单词:"+word(str))function word(dc){ let arr=dc.split(" "); let n=[]; for(var i=0;icom){ com=len } } console.log("最长语句有:"+com+"单词个") //输出单词个数最长的那个单词 console.log() let sum=[] for(var k=0;k
方法二:
let read =require("readline-sync");console.log("输入英语语句");let str=read.question("");function longword(str){ let arr=str.split(" ") let max=arr[0].length for(var i=1;imax){ max=arr[i].length; } } let arr2=[] for(let j=0;j