我写了一个代码来计算JavaScript中的模式,但它给了我一个错误。有人可以建议我在哪里犯错吗?
numbers = [6,4,77,66,6,69]
currentwinner = 1
winningfrequency = 0
counterindex = 0
contender = 1
contendercount = 0
while (counterindex< numbers.length){
contender = numbers[counterindex]
contender = 0
countingindex = 0
while (countingindex<numbers.length){
if (numbers[counterindex]==contender){
contendercount = 0
}
countingindex +=1
if (contendercount>winningfrequency){
contender = currentwinner
winningfrequency = contendercount
}
contenderindex +=1
}
mode = currentwinner
document.write(mode)
答案 0 :(得分:0)
正如@Frost在评论中所说,存在许多语法错误,包括:
还有一些逻辑错误:
for
循环?为此目的更好。