我有一些代码看起来像这样
\n<div class="topnav">\n <div>{{getGameView.Game.gameplayers[0].player.username}}</div>\n <p>VS</p>\n <div v-if="getGameView.Game.gameplayers.length > 1">\n\xe3\x80\x80 {{getGameView.Game.gameplayers[1].player.username}}\n\xe3\x80\x80</div>\n <div v-else>Waiting for opponent...</div>\n</div>\nRun Code Online (Sandbox Code Playgroud)\n打印出以下内容:NameVSName\n我试图使其在 Name 和 VS 之间有一些空格,但不知道如何做到这一点。
\n我想编写一个函数,将数组作为参数并返回可以被 12 整除的数字。但是,如果数组的数字大于 111,则它应该返回 0;我是这样写的:
function isDivisble(array) {
let numberOfNum = 0;
for(let i=0; i < array.length; i++) {
if(array[i] % 12 == 0 && array[i] < 111) {
numberOfNum = numberOfNum + 1 ;
} else {
numberofNum = 0;
}
}
return console.log(numberOfNum);
}
let test = [12, 24, 36, 44, 55, 255];
isDivisble(test)Run Code Online (Sandbox Code Playgroud)
我意识到这段代码单独检查当前数字是否可整除且不大于 111,而不是全局检查数组是否有大于 111 的数字,但我不明白如何进行一般数组检查。是否使用 if 语句编写 for 循环进行检查,然后在 if 语句中编写另一个 for 循环使它有点像意大利面?