mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
prettier fixes & added test cases for Project Euler problem 4 (#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 <omkarnath.parida@yocket.in>
This commit is contained in:
@ -16,7 +16,7 @@ function BinaryCountSetBits(a) {
|
|||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
while (a) {
|
while (a) {
|
||||||
a &= (a - 1)
|
a &= a - 1
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ describe('AutomorphicNumber', () => {
|
|||||||
|
|
||||||
test.each([
|
test.each([
|
||||||
{ n: -3, expected: false },
|
{ n: -3, expected: false },
|
||||||
{ n: -25 , expected: false },
|
{ n: -25, expected: false }
|
||||||
])('should return false when n is negetive', ({ n, expected }) => {
|
])('should return false when n is negetive', ({ n, expected }) => {
|
||||||
expect(isAutomorphic(n)).toBe(false)
|
expect(isAutomorphic(n)).toBe(false)
|
||||||
})
|
})
|
||||||
@ -21,7 +21,7 @@ describe('AutomorphicNumber', () => {
|
|||||||
{ n: 0, expected: true },
|
{ n: 0, expected: true },
|
||||||
{ n: 1, expected: true },
|
{ n: 1, expected: true },
|
||||||
{ n: 376, expected: true },
|
{ n: 376, expected: true },
|
||||||
{ n: 90625 , expected: true },
|
{ n: 90625, expected: true }
|
||||||
])('should return $expected when n is $n', ({ n, expected }) => {
|
])('should return $expected when n is $n', ({ n, expected }) => {
|
||||||
expect(isAutomorphic(n)).toBe(expected)
|
expect(isAutomorphic(n)).toBe(expected)
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// https://projecteuler.net/problem=6
|
// https://projecteuler.net/problem=6
|
||||||
|
|
||||||
export const squareDifference = (num = 100) => {
|
export const squareDifference = (num = 100) => {
|
||||||
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
|
let sumOfSquares = (num * (num + 1) * (2 * num + 1)) / 6
|
||||||
let sums = (num * (num + 1)) / 2
|
let sums = (num * (num + 1)) / 2
|
||||||
|
|
||||||
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
|
return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
|
||||||
|
11
Project-Euler/test/Problem004.test.js
Normal file
11
Project-Euler/test/Problem004.test.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { largestPalindromic } from '../Problem004.js'
|
||||||
|
|
||||||
|
describe('Largest Palindromic Number', () => {
|
||||||
|
test('if digit is 2', () => {
|
||||||
|
expect(largestPalindromic(2)).toBe(9009)
|
||||||
|
})
|
||||||
|
// Project Euler Condition Check
|
||||||
|
test('if digit is 3', () => {
|
||||||
|
expect(largestPalindromic(3)).toBe(906609)
|
||||||
|
})
|
||||||
|
})
|
@ -1,29 +1,29 @@
|
|||||||
import { binaryEquivalent } from "../BinaryEquivalent";
|
import { binaryEquivalent } from '../BinaryEquivalent'
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
test: 2,
|
test: 2,
|
||||||
expectedValue: "10"
|
expectedValue: '10'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: 0,
|
test: 0,
|
||||||
expectedValue: "0"
|
expectedValue: '0'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: 543,
|
test: 543,
|
||||||
expectedValue: "1000011111"
|
expectedValue: '1000011111'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: 4697621023,
|
test: 4697621023,
|
||||||
expectedValue: "100011000000000000000001000011111"
|
expectedValue: '100011000000000000000001000011111'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
describe("Binary Equivalent", () => {
|
describe('Binary Equivalent', () => {
|
||||||
test.each(tests)(
|
test.each(tests)(
|
||||||
"of $test should be $expectedValue",
|
'of $test should be $expectedValue',
|
||||||
({ test, expectedValue }) => {
|
({ test, expectedValue }) => {
|
||||||
expect(binaryEquivalent(test)).toBe(expectedValue);
|
expect(binaryEquivalent(test)).toBe(expectedValue)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user