Skip to content

Instantly share code, notes, and snippets.

@joefearnley
Created July 4, 2020 13:37
Show Gist options
  • Save joefearnley/1cb415586fc6fbd0e5f57223edce158b to your computer and use it in GitHub Desktop.
Save joefearnley/1cb415586fc6fbd0e5f57223edce158b to your computer and use it in GitHub Desktop.
The 10-Day JS Challenge - Day 10: Max Multiple
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