Travis build: 938

This commit is contained in:
30secondsofcode
2018-01-03 14:04:55 +00:00
parent 4e42e4bc4f
commit b692559f48
4 changed files with 77 additions and 12 deletions

View File

@ -8,12 +8,12 @@ If `divisor` is `-0` or `0` return `0`.
Otherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer.
Return the number of times the loop was executed, `i`.
``` js
```js
const howManyTimes = (num, divisor) => {
if(divisor === 1 || divisor === -1) return Infinity;
if(divisor === 0) return 0;
if (divisor === 1 || divisor === -1) return Infinity;
if (divisor === 0) return 0;
let i = 0;
while(Number.isInteger(num/divisor)){
while (Number.isInteger(num / divisor)) {
i++;
num = num / divisor;
}
@ -22,11 +22,11 @@ const howManyTimes = (num, divisor) => {
```
```js
howManyTimes(100,2); //2
howManyTimes(100,-2); //2
howManyTimes(100,2.5); //2
howManyTimes(100,3); //0
howManyTimes(100,0); //0
howManyTimes(100,1); //Infinity
howManyTimes(100,-1); //Infinity
howManyTimes(100, 2); //2
howManyTimes(100, -2); //2
howManyTimes(100, 2.5); //2
howManyTimes(100, 3); //0
howManyTimes(100, 0); //0
howManyTimes(100, 1); //Infinity
howManyTimes(100, -1); //Infinity
```