mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
Merge branch 'TheAlgorithms:master' into master
This commit is contained in:
10
Conversions/MeterToFeetConversion.js
Normal file
10
Conversions/MeterToFeetConversion.js
Normal file
@ -0,0 +1,10 @@
|
||||
// Foot: https://en.wikipedia.org/wiki/Foot_(unit)
|
||||
const feetToMeter = (feet) => {
|
||||
return feet*0.3048;
|
||||
}
|
||||
|
||||
const meterToFeet = (meter) => {
|
||||
return meter/0.3048;
|
||||
}
|
||||
|
||||
export { feetToMeter, meterToFeet }
|
13
Conversions/test/MeterToFeetConversion.test.js
Normal file
13
Conversions/test/MeterToFeetConversion.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { meterToFeet, feetToMeter } from "../MeterToFeetConversion";
|
||||
|
||||
describe('Testing conversion of Meter to Feet', () => {
|
||||
it('with feet value', () => {
|
||||
expect(meterToFeet(30.48)).toBe(100)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing conversion of Feet to Meter', () => {
|
||||
it('with feet value', () => {
|
||||
expect(feetToMeter(10)).toBe(3.048)
|
||||
})
|
||||
})
|
@ -46,6 +46,7 @@
|
||||
* [HexToDecimal](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/HexToDecimal.js)
|
||||
* [HexToRGB](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/HexToRGB.js)
|
||||
* [LowerCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/LowerCaseConversion.js)
|
||||
* [MeterToFeetConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/MeterToFeetConversion.js)
|
||||
* [OctToDecimal](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/OctToDecimal.js)
|
||||
* [RailwayTimeConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RailwayTimeConversion.js)
|
||||
* [RgbHsvConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RgbHsvConversion.js)
|
||||
@ -159,6 +160,7 @@
|
||||
* [FareyApproximation](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FareyApproximation.js)
|
||||
* [FermatPrimalityTest](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FermatPrimalityTest.js)
|
||||
* [Fibonacci](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Fibonacci.js)
|
||||
* [FigurateNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FigurateNumber.js)
|
||||
* [FindHcf](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FindHcf.js)
|
||||
* [FindLcm](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/FindLcm.js)
|
||||
* [GetEuclidGCD](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/GetEuclidGCD.js)
|
||||
|
76
Maths/FigurateNumber.js
Normal file
76
Maths/FigurateNumber.js
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
Problem Statment and Explanation :
|
||||
Triangular => https://en.wikipedia.org/wiki/Triangular_number
|
||||
Tetrahedral => https://en.wikipedia.org/wiki/Tetrahedral_number
|
||||
Pentatope => https://en.wikipedia.org/wiki/Pentatope_number
|
||||
|
||||
|
||||
Example:
|
||||
Triangular => (0, 1, 3, 6, 10, 15, 21, 28, 36, 45)
|
||||
Tetrahedral => (1, 4, 10, 20, 35, 56, 84, 120, 165,)
|
||||
Pentatope => (1, 5, 15, 35, 70, 126, 210, 330, 495)
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} number
|
||||
* @returns
|
||||
*/
|
||||
const isTriangular = (number) => {
|
||||
for (let i = 0; i <= number; i++) {
|
||||
if ((i * (i + 1)) / 2 === number) {
|
||||
return true
|
||||
} else if ((i * (i + 1)) / 2 > number) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} number
|
||||
* @returns
|
||||
*/
|
||||
const isTetrahedral = (number) => {
|
||||
for (let i = 1; i <= number; i++) {
|
||||
if ((i * (i + 1) * (i + 2)) / 6 === number) {
|
||||
return true
|
||||
} else if ((i * (i + 1) * (i + 2)) / 6 > number) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {*} number
|
||||
* @returns
|
||||
*/
|
||||
const isPentatope = (number) => {
|
||||
for (let i = 1; i <= number; i++) {
|
||||
if ((i * (i + 1) * (i + 2) * (i + 3)) / 24 === number) {
|
||||
return true
|
||||
} else if ((i * (i + 1) * (i + 2) * (i + 3)) / 24 > number) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} number
|
||||
* @returns
|
||||
*/
|
||||
let checkAll = (number) => {
|
||||
return {
|
||||
isTriangular: isTriangular(number),
|
||||
isTetrahedral: isTetrahedral(number),
|
||||
isPentatope: isPentatope(number)
|
||||
}
|
||||
}
|
||||
export { isTriangular }
|
||||
export { isTetrahedral }
|
||||
export { isPentatope }
|
||||
export { checkAll }
|
72
Maths/test/FigurateNumber.test.js
Normal file
72
Maths/test/FigurateNumber.test.js
Normal file
@ -0,0 +1,72 @@
|
||||
import {
|
||||
isTriangular,
|
||||
isTetrahedral,
|
||||
isPentatope,
|
||||
checkAll
|
||||
} from '../FigurateNumber'
|
||||
|
||||
describe('FigurateNumber', () => {
|
||||
it('Triangular : should return true', () => {
|
||||
expect(isTriangular(1)).toEqual(true)
|
||||
})
|
||||
it('Triangular : should return true', () => {
|
||||
expect(isTriangular(3)).toEqual(true)
|
||||
})
|
||||
|
||||
it('Triangular : should return false', () => {
|
||||
expect(isTriangular(5)).toEqual(false)
|
||||
})
|
||||
|
||||
it('Triangular : should return true', () => {
|
||||
expect(isTriangular(171)).toEqual(true)
|
||||
})
|
||||
/** End */
|
||||
|
||||
it('Tetrahedral : should return true', () => {
|
||||
expect(isTetrahedral(1)).toEqual(true)
|
||||
})
|
||||
it('Tetrahedral : should return true', () => {
|
||||
expect(isTetrahedral(4)).toEqual(true)
|
||||
})
|
||||
|
||||
it('Tetrahedral : should return false', () => {
|
||||
expect(isTetrahedral(3)).toEqual(false)
|
||||
})
|
||||
|
||||
it('Tetrahedral : should return true', () => {
|
||||
expect(isTetrahedral(165)).toEqual(true)
|
||||
})
|
||||
|
||||
/** End */
|
||||
it('Pentatope : should return true', () => {
|
||||
expect(isPentatope(1)).toEqual(true)
|
||||
})
|
||||
it('Pentatope : should return true', () => {
|
||||
expect(isPentatope(5)).toEqual(true)
|
||||
})
|
||||
|
||||
it('Pentatope : should return false', () => {
|
||||
expect(isPentatope(3)).toEqual(false)
|
||||
})
|
||||
|
||||
it('Pentatope : should return true', () => {
|
||||
expect(isPentatope(1001)).toEqual(true)
|
||||
})
|
||||
/** End */
|
||||
|
||||
it('Check All : should return all true',() => {
|
||||
expect(checkAll(1)).toEqual({
|
||||
isTriangular: true,
|
||||
isTetrahedral: true,
|
||||
isPentatope: true
|
||||
})
|
||||
})
|
||||
|
||||
it('Check All : should return all true,true,false',() => {
|
||||
expect(checkAll(15)).toEqual({
|
||||
isTriangular: true,
|
||||
isTetrahedral: false,
|
||||
isPentatope: true
|
||||
})
|
||||
})
|
||||
})
|
13376
package-lock.json
generated
13376
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user