Skip to content

Commit 9a87526

Browse files
prettier fixes & added test cases for Project Euler problem 4 (TheAlgorithms#1566)
* 📦 NEW: Added solution for ProjectEuler-007 * 🐛 FIX: Spelling mistake fixes * 👌 IMPROVE: changed variable name from `inc` to `candidateValue` and thrown error in case of invalid input * 👌 IMPROVE: Modified the code * 👌 IMPROVE: Added test case for ProjectEuler Problem001 * 👌 IMPROVE: Added test cases for Project Euler Problem 4 * 👌 IMPROVE: auto prettier fixes --------- Co-authored-by: Omkarnath Parida <[email protected]>
1 parent fb134b1 commit 9a87526

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

Bit-Manipulation/BinaryCountSetBits.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function BinaryCountSetBits(a) {
1616

1717
let count = 0
1818
while (a) {
19-
a &= (a - 1)
19+
a &= a - 1
2020
count++
2121
}
2222

Maths/AutomorphicNumber.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export const isAutomorphic = (n) => {
3535
n = Math.floor(n / 10)
3636
n_sq = Math.floor(n_sq / 10)
3737
}
38-
38+
3939
return true
4040
}

Maths/test/AutomorphicNumber.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ describe('AutomorphicNumber', () => {
99
})
1010

1111
test.each([
12-
{ n: -3 , expected: false },
13-
{ n: -25 , expected: false },
12+
{ n: -3, expected: false },
13+
{ n: -25, expected: false }
1414
])('should return false when n is negetive', ({ n, expected }) => {
1515
expect(isAutomorphic(n)).toBe(false)
1616
})
1717

1818
test.each([
19-
{ n: 7 , expected: false },
20-
{ n: 83 , expected: false },
21-
{ n: 0 , expected: true },
22-
{ n: 1 , expected: true },
23-
{ n: 376 , expected: true },
24-
{ n: 90625 , expected: true },
19+
{ n: 7, expected: false },
20+
{ n: 83, expected: false },
21+
{ n: 0, expected: true },
22+
{ n: 1, expected: true },
23+
{ n: 376, expected: true },
24+
{ n: 90625, expected: true }
2525
])('should return $expected when n is $n', ({ n, expected }) => {
2626
expect(isAutomorphic(n)).toBe(expected)
2727
})

Project-Euler/Problem006.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// https://projecteuler.net/problem=6
22

33
export const squareDifference = (num = 100) => {
4-
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
5-
let sums = (num*(num+1))/2
6-
4+
let sumOfSquares = (num * (num + 1) * (2 * num + 1)) / 6
5+
let sums = (num * (num + 1)) / 2
6+
77
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
88
}

Project-Euler/test/Problem004.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { largestPalindromic } from '../Problem004.js'
2+
3+
describe('Largest Palindromic Number', () => {
4+
test('if digit is 2', () => {
5+
expect(largestPalindromic(2)).toBe(9009)
6+
})
7+
// Project Euler Condition Check
8+
test('if digit is 3', () => {
9+
expect(largestPalindromic(3)).toBe(906609)
10+
})
11+
})
+24-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { binaryEquivalent } from "../BinaryEquivalent";
1+
import { binaryEquivalent } from '../BinaryEquivalent'
22

33
const tests = [
4-
{
5-
test: 2,
6-
expectedValue: "10"
7-
},
8-
{
9-
test: 0,
10-
expectedValue: "0"
11-
},
12-
{
13-
test: 543,
14-
expectedValue: "1000011111"
15-
},
16-
{
17-
test: 4697621023,
18-
expectedValue: "100011000000000000000001000011111"
19-
}
4+
{
5+
test: 2,
6+
expectedValue: '10'
7+
},
8+
{
9+
test: 0,
10+
expectedValue: '0'
11+
},
12+
{
13+
test: 543,
14+
expectedValue: '1000011111'
15+
},
16+
{
17+
test: 4697621023,
18+
expectedValue: '100011000000000000000001000011111'
19+
}
2020
]
2121

22-
describe("Binary Equivalent", () => {
23-
test.each(tests)(
24-
"of $test should be $expectedValue",
25-
({test, expectedValue}) => {
26-
expect(binaryEquivalent(test)).toBe(expectedValue);
27-
}
28-
)
22+
describe('Binary Equivalent', () => {
23+
test.each(tests)(
24+
'of $test should be $expectedValue',
25+
({ test, expectedValue }) => {
26+
expect(binaryEquivalent(test)).toBe(expectedValue)
27+
}
28+
)
2929
})

Search/InterpolationSearch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ export function interpolationSearch(arr, key) {
3636
}
3737

3838
return -1
39-
}
39+
}

0 commit comments

Comments
 (0)