Skip to content

[pull] master from TheAlgorithms:master #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* [ROT13](Ciphers/ROT13.js)
* [VigenereCipher](Ciphers/VigenereCipher.js)
* [XORCipher](Ciphers/XORCipher.js)
* **Compression**
* [RLE](Compression/RLE.js)
* **Conversions**
* [ArbitraryBase](Conversions/ArbitraryBase.js)
* [ArrayBufferToBase64](Conversions/ArrayBufferToBase64.js)
Expand Down Expand Up @@ -285,6 +287,7 @@
* [Problem016](Project-Euler/Problem016.js)
* [Problem017](Project-Euler/Problem017.js)
* [Problem018](Project-Euler/Problem018.js)
* [Problem019](Project-Euler/Problem019.js)
* [Problem020](Project-Euler/Problem020.js)
* [Problem021](Project-Euler/Problem021.js)
* [Problem023](Project-Euler/Problem023.js)
Expand Down
6 changes: 1 addition & 5 deletions Maths/AverageMean.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const mean = (nums) => {
throw new TypeError('Invalid Input')
}

// This loop sums all values in the 'nums' array using forEach loop
const sum = nums.reduce((sum, cur) => sum + cur, 0)

// Divide sum by the length of the 'nums' array.
return sum / nums.length
return nums.reduce((sum, cur) => sum + cur, 0) / nums.length
}

export { mean }
8 changes: 3 additions & 5 deletions Project-Euler/Problem005.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ Smallest multiple
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
export const findSmallestMultiple = (maxDivisor) => {
const divisors = Array.from({ length: maxDivisor }, (_, i) => i + 1)
let num = maxDivisor + 1
let result

while (!result) {
Expand Down
12 changes: 12 additions & 0 deletions Project-Euler/test/Problem005.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from 'vitest'
import { findSmallestMultiple } from '../Problem005.js'

describe.concurrent('Find smallest multiple', () => {
test.each([
[10, 2520],
[15, 360360],
[20, 232792560]
])('max divisor -> %i, smallest multiple -> %i', (a, expected) => {
expect(findSmallestMultiple(a)).toBe(expected)
})
})
15 changes: 15 additions & 0 deletions Project-Euler/test/Problem014.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from 'vitest'
import { findLongestCollatzSequence } from '../Problem014.js'

describe('Longest Collatz Sequence', () => {
test.each([
[2, 1],
[13, 9],
[1000000, 837799]
])(
'if limit is %i, then the Longest Collatz Sequence will be %i',
(a, expected) => {
expect(findLongestCollatzSequence(a)).toBe(expected)
}
)
})
Loading
Loading