-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3cc6d39
Adding Pythagoras Theorem
cwh0430 214fc17
Update Code Format
cwh0430 51f32d7
Create PythagorasTheorem.test.js
cwh0430 36996b8
Updated File Name and Deduplication
cwh0430 12aa4ca
Updated File Name and Deduplication
cwh0430 978a100
Update PythagoreanTheorem.js
cwh0430 b1ae147
Update on Indentation
cwh0430 3ae304c
Updated function's name
cwh0430 5cd94d8
Update PythagoreanTheorem.test.js
cwh0430 af5d82b
Update PythagoreanTheorem.js
cwh0430 153f405
Update PythagoreanTheorem.test.js
cwh0430 0dab0e4
Update PythagoreanTheorem.js
cwh0430 462f4f1
Update PythagoreanTheorem.js
cwh0430 6a27fa2
Update PythagoreanTheorem.test.js
cwh0430 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.