Complete the function that takes 3 numbers x, y and k
(where x ≤ y
), and returns the number of integers within the range [x..y]
(both ends included) that are divisible by k
.
More scientifically: { i : x ≤ i ≤ y, i mod k = 0 }
Example
Given x = 6, y = 11, k = 2
the function should return 3
, because there are three numbers divisible by 2
between 6
and 11
: 6, 8, 10
function divisibleCount(x, y, k) { while(x % k) { x++; } return parseInt(((y - x) / k) + 1); }
x
가 k로 나눠질 때까지 증가시킴.
그리고y
에서x
를 뺀 수를k
로 나눈 몫에 1을 더한 값을return
하면 됨.