Skip to content
Prev Previous commit
Next Next commit
chore: code style
  • Loading branch information
defaude committed Oct 2, 2023
commit 2fe0ba49be10d79628d8ccdffe2d88d1455aa3ad
4 changes: 1 addition & 3 deletions Conversions/LengthConversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ const lengthConversion = (length, fromUnit, toUnit) => {
return convertedLength
}

export {
lengthConversion
}
export { lengthConversion }
73 changes: 32 additions & 41 deletions Conversions/test/LengthConversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,43 @@ import { lengthConversion } from '../LengthConversion.js'

describe('LengthConversion', () => {
it.each`
length | fromUnit | toUnit | expected
${10} | ${'km'} | ${'m'} | ${10000}
${100} | ${'m'} | ${'km'} | ${0.1}
${5} | ${'cm'} | ${'mm'} | ${50}
${12} | ${'ft'} | ${'inch'}| ${144.00000000000003}
`(
'converts $length $fromUnit to $toUnit',
({ length, fromUnit, toUnit, expected }) => {
try {
const result = lengthConversion(length, fromUnit, toUnit)
expect(result).toBe(expected)
} catch (error) {
expect(error).toBeUndefined()
}
length | fromUnit | toUnit | expected
${10} | ${'km'} | ${'m'} | ${10000}
${100} | ${'m'} | ${'km'} | ${0.1}
${5} | ${'cm'} | ${'mm'} | ${50}
${12} | ${'ft'} | ${'inch'} | ${144.00000000000003}
`('converts $length $fromUnit to $toUnit', ({ length, fromUnit, toUnit, expected }) => {
try {
const result = lengthConversion(length, fromUnit, toUnit)
expect(result).toBe(expected)
} catch (error) {
expect(error).toBeUndefined()
}
)
})

it.each`
length | fromUnit | toUnit | expected
${10} | ${'m'} | ${'km'} | ${0.01}
${1000}| ${'mm'} | ${'cm'} | ${100}
${1} | ${'inch'}| ${'ft'} | ${0.08333333333}
`(
'converts $length $fromUnit to $toUnit (vice versa)',
({ length, fromUnit, toUnit, expected }) => {
try {
const result = lengthConversion(length, fromUnit, toUnit)
expect(result).toBeCloseTo(expected, 10) // Close comparison due to floating-point precision
} catch (error) {
expect(error).toBeUndefined()
}
length | fromUnit | toUnit | expected
${10} | ${'m'} | ${'km'} | ${0.01}
${1000} | ${'mm'} | ${'cm'} | ${100}
${1} | ${'inch'} | ${'ft'} | ${0.08333333333}
`('converts $length $fromUnit to $toUnit (vice versa)', ({ length, fromUnit, toUnit, expected }) => {
try {
const result = lengthConversion(length, fromUnit, toUnit)
expect(result).toBeCloseTo(expected, 10) // Close comparison due to floating-point precision
} catch (error) {
expect(error).toBeUndefined()
}
)
})

it.each`
length | fromUnit | toUnit | expectedError
${10} | ${'km'} | ${'invalid'} | ${'Invalid units'}
${5} | ${'invalid'} | ${'m'} | ${'Invalid units'}
`(
'returns error message for invalid units: $fromUnit to $toUnit',
({ length, fromUnit, toUnit, expectedError }) => {
try {
lengthConversion(length, fromUnit, toUnit)
} catch (error) {
expect(error.message).toBe(expectedError)
}
length | fromUnit | toUnit | expectedError
${10} | ${'km'} | ${'invalid'} | ${'Invalid units'}
${5} | ${'invalid'} | ${'m'} | ${'Invalid units'}
`('returns error message for invalid units: $fromUnit to $toUnit', ({ length, fromUnit, toUnit, expectedError }) => {
try {
lengthConversion(length, fromUnit, toUnit)
} catch (error) {
expect(error.message).toBe(expectedError)
}
)
})
})
5 changes: 1 addition & 4 deletions Maths/QuadraticRoots.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ const quadraticRoots = (a, b, c) => {
} else {
// Two real roots
const sqrtDiscriminant = Math.sqrt(discriminant)
return [
(-b + sqrtDiscriminant) / (2 * a),
(-b - sqrtDiscriminant) / (2 * a)
]
return [(-b + sqrtDiscriminant) / (2 * a), (-b - sqrtDiscriminant) / (2 * a)]
}
}

Expand Down
16 changes: 8 additions & 8 deletions String/ReverseString.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ function ReverseStringIterative(string) {

/**
*
* @author dev-madhurendra
* Reverses a number by converting it to a string.
*
* @param {string} str - The number to reverse.
* @returns {string} The reversed number.
*
* @example
* const reversed = reverseString("hello"); // Returns olleh
* @author dev-madhurendra
* Reverses a number by converting it to a string.
*
* @param {string} str - The number to reverse.
* @returns {string} The reversed number.
*
* @example
* const reversed = reverseString("hello"); // Returns olleh
*/

const ReverseStringIterativeInplace = (str) => [...str].reverse().join('')
Expand Down