创建一个函数,它接受一个数字数组作为参数。如果数字7出现在数组中,返回“Boom!”。否则,返回“数组中没有数字7”。
最后两个测试失败了,我认为这是因为它正在寻找一个
function sevenBoom(arr) {
if (arr.includes(7)) {
return "Boom!"
}
return "there is no 7 in the array"
}
测试
Test.assertEquals(sevenBoom([2, 6, 7, 9, 3]), "Boom!")
Test.assertEquals(sevenBoom([33, 68, 400, 5]), "there is no 7 in the array")
Test.assertEquals(sevenBoom([86, 48, 100, 66]), "there is no 7 in the array")
Test.assertEquals(sevenBoom([76, 55, 44, 32]), "Boom!")
Test.assertEquals(sevenBoom([35, 4, 9, 37]), "Boom!")
最后两个测试失败了,我认为这是因为它正在寻找一个
7
,而不仅仅是在数字本身中有一个7
。我该如何纠正这个问题?
非重复问题
这与子字符串或字符串无关。为什么人们喜欢将事物标记为重复?
37
。 - user120765107
。你在哪里看到的字符串?我有什么遗漏吗?这与数组和数字有关。 - user12076510