Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adding Pythagoras Theorem #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cwh0430 wants to merge 14 commits into TheAlgorithms:master from cwh0430:patch-1
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
3cc6d39
Adding Pythagoras Theorem
cwh0430 Jul 30, 2022
214fc17
Update Code Format
cwh0430 Jul 30, 2022
51f32d7
Create PythagorasTheorem.test.js
cwh0430 Jul 31, 2022
36996b8
Updated File Name and Deduplication
cwh0430 Jul 31, 2022
12aa4ca
Updated File Name and Deduplication
cwh0430 Jul 31, 2022
978a100
Update PythagoreanTheorem.js
cwh0430 Jul 31, 2022
b1ae147
Update on Indentation
cwh0430 Jul 31, 2022
3ae304c
Updated function's name
cwh0430 Aug 3, 2022
5cd94d8
Update PythagoreanTheorem.test.js
cwh0430 Aug 3, 2022
af5d82b
Update PythagoreanTheorem.js
cwh0430 Aug 3, 2022
153f405
Update PythagoreanTheorem.test.js
cwh0430 Aug 5, 2022
0dab0e4
Update PythagoreanTheorem.js
cwh0430 Aug 5, 2022
462f4f1
Update PythagoreanTheorem.js
cwh0430 Aug 5, 2022
6a27fa2
Update PythagoreanTheorem.test.js
cwh0430 Aug 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Maths/PythagoreanTheorem.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @function calcHypothenuse
* @description Calculate the length of hypothenuse of triangle
* @param {Integer} side1 - Integer
* @param {Integer} side2 - Integer
* @return {Integer} - hypothenuse
* @see [calcHypothenuse](https://en.wikipedia.org/wiki/Pythagorean_theorem)
* @example calcHypothenuse(2, 3) = 4
*/
const calcHypothenuse = (side1, side2) => {
const hypothenuse = Math.sqrt((side1 ** 2) + (side2 ** 2))
return hypothenuse
}
/**
* @function calcOtherSide
* @description Calculate the length of other sides of triangle
* @param {Integer} hypothenuse - Integer
* @param {Integer} side1 - Integer
* @return {Integer} - side2
* @see [calcOtherSide](https://en.wikipedia.org/wiki/Pythagorean_theorem)
* @example calcOtherSide(4, 3) = 2
*/
const calcOtherSide = (hypothenuse, side1) => {
if (side1 >= hypothenuse) {
return 'Length of side1 must be smaller than hypothenuse'
}
const side2 = Math.sqrt((hypothenuse ** 2) - (side1 ** 2))
return side2
}

export {
calcHypothenuse,
calcOtherSide
}
16 changes: 16 additions & 0 deletions Maths/test/PythagoreanTheorem.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as pytheorem from '../PythagoreanTheorem'

test('Testing on hypothenuse calculation', () => {
const hypothenuse = pytheorem.calcHypothenuse(6.0, 8.0)
expect(hypothenuse).toBe(10.0)
})

test('Testing on other sides calculation', () => {
const side = pytheorem.calcOtherSide(10.0, 6.0)
expect(side).toBe(8.0)
})

test('Testing on other sides calculation', () => {
const side = pytheorem.calcOtherSide(6.0, 10.0)
expect(side).toBe('Length of side1 must be smaller than hypothenuse')
})

AltStyle によって変換されたページ (->オリジナル) /