Don't give me five!

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
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章