In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!
Examples:
1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12
The result may contain fives. ;-)
The start number will always be smaller than the end number. Both numbers can be also negative!
代码:
function dontGiveMeFive(start, end) {
var r=[],i=start;
while(i<end+1){
var str= i.toString();
if(str.indexOf(5)==-1){
r.push(i++)
}else{
i++
}
}
return r.length
}
本文介绍了一个有趣的编程挑战——实现一个函数,该函数接收两个参数(起始和结束数值),并返回此区间内(包括边界值)不包含数字5的所有整数的数量。通过具体的例子展示了如何使用JavaScript来完成这个任务。

1288

被折叠的 条评论
为什么被折叠?



