Skip to content
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

Implement Pythagorean Algorithm #1091

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/algorithms/math/pythagorean-theorem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Pythagorean theorem: the area of the square whose side is the hypotenuse
(the side opposite the right angle) is equal to the sum of
the areas of the squares on the other two sides.

## References:
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwjnuNvt9v6CAxXyv4kEHWYeCoAQFnoECC4QAQ&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPythagorean_theorem&usg=AOvVaw3T92yCCxl4W1aa8hM6ft__&opi=89978449
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import isPythagoreanTriangle from '../pythagoreanTheorem';

describe('isPythagoreanTriangle', () => {
it('should return true if hyperparameters satisfied the pythagorean theorem, otherwise return false', () => {
expect(isPythagoreanTriangle(0, 0, 0)).toEqual(false);
expect(isPythagoreanTriangle(-1, 2, 5)).toEqual(false);
expect(isPythagoreanTriangle(3, 4, 5)).toEqual(true);
expect(isPythagoreanTriangle(3, 4, -5)).toEqual(false);
expect(isPythagoreanTriangle(-1, -1, 1)).toEqual(false);
expect(isPythagoreanTriangle(3, 4, 25)).toEqual(false);
});
});
9 changes: 9 additions & 0 deletions src/algorithms/math/pythagorean-theorem/pythagoreanTheorem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @param {number} a
* @param {number} b
* @param {number} c
* @return {boolean}
*/
export default function isPythagoreanTriangle(a, b, c) {
return (a <= 0 || b <= 0 || c <= 0) ? false : ((a * a) + (b * b) === (c * c));
}