Use a regular expression to test if a word is just spaces, and report an error.
function megaFriend(str) {
var wordLength = 0;
var biggestWord;
for (var i = 0; i < str.length; i++) {
if (str[i].match(/^s+$/)) {
alert("Spaces entered");
return false;
}
if (str[i].length > wordLength) {
var wordLength = str[i].length;
biggestWord = str[i];
}
}
return biggestWord;
}
console.log(megaFriend(['Nahid', 'Hassan', 'Ahugoggghs', ' ']));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…