diff --git a/snippets_archive/howManyTimes.md b/snippets_archive/howManyTimes.md deleted file mode 100644 index e0569e0bf..000000000 --- a/snippets_archive/howManyTimes.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: howManyTimes -tags: math,beginner ---- - -Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer. -Works for both negative and positive integers. - -If `divisor` is `-1` or `1` return `Infinity`. -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 -const howManyTimes = (num, divisor) => { - if (divisor === 1 || divisor === -1) return Infinity; - if (divisor === 0) return 0; - let i = 0; - while (Number.isInteger(num / divisor)) { - i++; - num = num / divisor; - } - return i; -}; -``` - -```js -howManyTimes(100, 2); // 2 -howManyTimes(100, 2.5); // 2 -howManyTimes(100, 0); // 0 -howManyTimes(100, -1); // Infinity -``` \ No newline at end of file diff --git a/test/howManyTimes.test.js b/test/howManyTimes.test.js deleted file mode 100644 index 7aa6f4301..000000000 --- a/test/howManyTimes.test.js +++ /dev/null @@ -1,17 +0,0 @@ -const {howManyTimes} = require('./_30s.js'); - -test('howManyTimes is a Function', () => { - expect(howManyTimes).toBeInstanceOf(Function); -}); -test('howManyTimes returns the correct result', () => { - expect(howManyTimes(100, 2)).toBe(2); -}); -test('howManyTimes returns the correct result', () => { - expect(howManyTimes(100, 2.5)).toBe(2); -}); -test('howManyTimes returns the correct result', () => { - expect(howManyTimes(100, 0)).toBe(0); -}); -test('howManyTimes returns the correct result', () => { - expect(howManyTimes(100, -1)).toBe(Infinity); -});