Skip to content

Commit ff314a2

Browse files
authored
Add tests for Project Euler Problem 5 + minor refactor (TheAlgorithms#1691)
1 parent 18da83a commit ff314a2

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

DIRECTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* [ROT13](Ciphers/ROT13.js)
3636
* [VigenereCipher](Ciphers/VigenereCipher.js)
3737
* [XORCipher](Ciphers/XORCipher.js)
38+
* **Compression**
39+
* [RLE](Compression/RLE.js)
3840
* **Conversions**
3941
* [ArbitraryBase](Conversions/ArbitraryBase.js)
4042
* [ArrayBufferToBase64](Conversions/ArrayBufferToBase64.js)
@@ -285,6 +287,7 @@
285287
* [Problem016](Project-Euler/Problem016.js)
286288
* [Problem017](Project-Euler/Problem017.js)
287289
* [Problem018](Project-Euler/Problem018.js)
290+
* [Problem019](Project-Euler/Problem019.js)
288291
* [Problem020](Project-Euler/Problem020.js)
289292
* [Problem021](Project-Euler/Problem021.js)
290293
* [Problem023](Project-Euler/Problem023.js)

Project-Euler/Problem005.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ Smallest multiple
55
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
66
*/
77

8-
export const findSmallestMultiple = () => {
9-
const divisors = [
10-
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2
11-
]
12-
let num = 21
8+
export const findSmallestMultiple = (maxDivisor) => {
9+
const divisors = Array.from({ length: maxDivisor }, (_, i) => i + 1)
10+
let num = maxDivisor + 1
1311
let result
1412

1513
while (!result) {

Project-Euler/test/Problem005.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect } from 'vitest'
2+
import { findSmallestMultiple } from '../Problem005.js'
3+
4+
describe.concurrent('Find smallest multiple', () => {
5+
test.each([
6+
[10, 2520],
7+
[15, 360360],
8+
[20, 232792560]
9+
])('max divisor -> %i, smallest multiple -> %i', (a, expected) => {
10+
expect(findSmallestMultiple(a)).toBe(expected)
11+
})
12+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy