https://www.codewars.com/kata/5813d19765d81c592200001a
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
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!
I'm very curious for your solutions and the way you solve it. Maybe someone of you will find an easy pure mathematics solution.
Have fun coding it and please don't forget to vote and rank this kata! :-)
I have also created other katas. Take a look if you enjoyed this kata!
코드
function dontGiveMeFive(start, end){
let count = 0;
for(let i = start; i <= end; i++){
if(!i.toString().split('').includes('5')) count++;
}
return count;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Mexican Wave (6 kyu) / JavaScript (0) | 2023.04.24 |
---|---|
[Codewars] Weight for weight (5 kyu) / JavaScript (0) | 2023.04.23 |
[Codewars] Find the stray number (7 kyu) / JavaScript (0) | 2023.04.20 |
[Codewars] Twice as old (8 kyu) / JavaScript (0) | 2023.04.20 |
[Codewars] Super Duper Easy (8 kyu) / JavaScript (0) | 2023.04.19 |
댓글