This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getTriangleType): get type of a Triangle (#252)
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,19 @@ | ||
export default getTriangleType | ||
|
||
/** | ||
* Original Source: https://stackoverflow.com/questions/12491976 | ||
* | ||
* This function will return the type of a triangle, given its sides (a, b, c) length. It's a copy. | ||
* | ||
* @param {String} a - The sides to determine which triangle it belongs to | ||
* @param {String} b - The sides to determine which triangle it belongs to | ||
* @param {String} c - The sides to determine which triangle it belongs to | ||
* @return {String} (Equilateral, Isosceles and Scalene) - The type of triangle | ||
*/ | ||
function getTriangleType(a, b, c) { | ||
return ( | ||
(a === b && b === c && 'Equilateral') || | ||
((a === b || a === c || b === c) && 'Isosceles') || | ||
'Scalene' | ||
) | ||
} |
This file contains 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
This file contains 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,29 @@ | ||
import test from 'ava' | ||
import {getTriangleType} from '../src' | ||
|
||
test('gets the type of a triangle when Equilateral', t => { | ||
const a = 10 | ||
const b = 10 | ||
const c = 10 | ||
const expected = 'Equilateral' | ||
const actual = getTriangleType(a, b, c) | ||
t.deepEqual(actual, expected) | ||
}) | ||
|
||
test('gets the type of a triangle when Isosceles', t => { | ||
const a = 10 | ||
const b = 20 | ||
const c = 20 | ||
const expected = 'Isosceles' | ||
const actual = getTriangleType(a, b, c) | ||
t.deepEqual(actual, expected) | ||
}) | ||
|
||
test('gets the type of a triangle when Scalene', t => { | ||
const a = 10 | ||
const b = 20 | ||
const c = 30 | ||
const expected = 'Scalene' | ||
const actual = getTriangleType(a, b, c) | ||
t.deepEqual(actual, expected) | ||
}) |