mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
chore: Merge pull request #633 from AbhinavXT/DegreeToRadian
Added DegreeToRadian.js and DegreeToRadian.test.js in Maths directory
This commit is contained in:
23
Maths/DegreeToRadian.js
Normal file
23
Maths/DegreeToRadian.js
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Radian : https://en.wikipedia.org/wiki/Radian
|
||||
* Degree : https://en.wikipedia.org/wiki/Degree_(angle)
|
||||
*
|
||||
* Angle in Radian = ( Angle in Degree ) x ( pi / 180 )
|
||||
*
|
||||
* Example :
|
||||
* Question : Convert 90 degree to radian
|
||||
* So, Angle in Degree = 90
|
||||
*
|
||||
* Solution :
|
||||
* Angle in Radian = ( 90 ) x ( pi / 180 ) = pi / 2
|
||||
*
|
||||
* So, 90 degree is equal to pi / 2 radian
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {number} degree
|
||||
* @return {number}
|
||||
*/
|
||||
export const degreeToRadian = (degree) => {
|
||||
return degree * (Math.PI / 180)
|
||||
}
|
21
Maths/test/DegreeToRadian.test.js
Normal file
21
Maths/test/DegreeToRadian.test.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { degreeToRadian } from '../DegreeToRadian'
|
||||
|
||||
test('should convert degree to radian:', () => {
|
||||
const radianEqual = degreeToRadian(0)
|
||||
expect(radianEqual).toBe(0)
|
||||
})
|
||||
|
||||
test('should convert degree to radian:', () => {
|
||||
const radianEqual = degreeToRadian(45)
|
||||
expect(radianEqual).toBe(Math.PI / 4)
|
||||
})
|
||||
|
||||
test('should convert degree to radian:', () => {
|
||||
const radianEqual = degreeToRadian(90)
|
||||
expect(radianEqual).toBe(Math.PI / 2)
|
||||
})
|
||||
|
||||
test('should convert degree to radian:', () => {
|
||||
const radianEqual = degreeToRadian(180)
|
||||
expect(radianEqual).toBe(Math.PI)
|
||||
})
|
Reference in New Issue
Block a user