我正在处理一些JS Coderbyte挑战,即使我让所有测试用例都正确,但它说我弄错了。特别是这个挑战是寻找最长的词。有人有这个问题吗?任何帮助表示赞赏。
function LongestWord(sen) {
var remove = sen.replace(/[^a-zA-Z 0-9]+/g,"");
var keep = remove.split(" ");
var hold = 0;
var word = 0;
for(var i = 0; i < keep.length; i++) {
if(keep[i].length > hold) {
hold = keep[i].length;
word = keep[i];
}
}
return word;
}
LongestWord( "a b c dee");
Ex test cases:
"I love dogs" should output "love"
"a confusing /:sentence:/[ this is not!!!!!!!~" should output "confusing"
"a beautiful sentence^&!" should output "beautiful"
"a b c dee" should output "dee"