mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-18 09:23:55 +08:00

* chore: Switch to Node 20 + Vitest * chore: migrate to vitest mock functions * chore: code style (switch to prettier) * test: re-enable long-running test Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime! see #1193 * chore: code style * chore: fix failing tests * Updated Documentation in README.md * Update contribution guidelines to state usage of Prettier * fix: set prettier printWidth back to 80 * chore: apply updated code style automatically * fix: set prettier line endings to lf again * chore: apply updated code style automatically --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
23 lines
575 B
JavaScript
23 lines
575 B
JavaScript
/*
|
|
Smallest multiple
|
|
|
|
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
|
|
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
|
*/
|
|
|
|
export const findSmallestMultiple = () => {
|
|
const divisors = [
|
|
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2
|
|
]
|
|
let num = 21
|
|
let result
|
|
|
|
while (!result) {
|
|
const isDivisibleByAll = divisors.every((divisor) => num % divisor === 0)
|
|
if (isDivisibleByAll) result = num
|
|
else num++
|
|
}
|
|
|
|
return result
|
|
}
|