Created
July 4, 2020 13:37
-
-
Save joefearnley/1cb415586fc6fbd0e5f57223edce158b to your computer and use it in GitHub Desktop.
The 10-Day JS Challenge - Day 10: Max Multiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const maxMultiple = (divisor, bound) => { | |
let result = divisor; | |
for (let i = divisor; i <= bound; i *= divisor) { | |
result = i; | |
} | |
return result; | |
} | |
describe('maxMultiple()', () => { | |
it('returns largest integer up to boundary - 3', () => { | |
// arrange | |
const divisor = 3; | |
const bound = 10; | |
// act | |
const result = maxMultiple(divisor, bound); | |
// log | |
console.log("result: ", result); | |
// assert | |
expect(result).toBe(9); | |
}); | |
it('returns largest integer up to boundary - 12', () => { | |
// arrange | |
const divisor = 12; | |
const bound = 250000; | |
// act | |
const result = maxMultiple(divisor, bound); | |
// log | |
console.log("result: ", result); | |
// assert | |
expect(result).toBe(248832); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment