请参考- https://jsfiddle.net/jy5p509c/。
最后一个单词没有被反转并且没有在最终结果中输出。不确定缺少什么。
var a = "who all are coming to the party and merry around in somewhere";
res = ""; resarr = [];
for(i=0 ;i<a.length; i++) {
if(a[i] == " ") {
res+= resarr.reverse().join("")+" ";
resarr = [];
}
else {
resarr.push(a[i]);
}
}
console.log(res);
最后一个单词没有被反转并且没有在最终结果中输出。不确定缺少什么。