Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 8b80d3c

Browse files
bolah2009Kent C. Dodds
authored and
Kent C. Dodds
committed
feat(getTriangleType): get type of a Triangle (#252)
1 parent c8ee1a3 commit 8b80d3c

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/getTriangleType.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default getTriangleType
2+
3+
/**
4+
* Original Source: https://stackoverflow.com/questions/12491976
5+
*
6+
* This function will return the type of a triangle, given its sides (a, b, c) length. It's a copy.
7+
*
8+
* @param {String} a - The sides to determine which triangle it belongs to
9+
* @param {String} b - The sides to determine which triangle it belongs to
10+
* @param {String} c - The sides to determine which triangle it belongs to
11+
* @return {String} (Equilateral, Isosceles and Scalene) - The type of triangle
12+
*/
13+
function getTriangleType(a, b, c) {
14+
return (
15+
(a === b && b === c && 'Equilateral') ||
16+
((a === b || a === c || b === c) && 'Isosceles') ||
17+
'Scalene'
18+
)
19+
}

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import clone from './clone'
9393
import arrMultiply from './array-multiplier'
9494
import second from './second'
9595
import armstrong from './armstrong'
96+
import getTriangleType from './getTriangleType'
9697

9798
export {
9899
reverseArrayInPlace,
@@ -190,4 +191,6 @@ export {
190191
arrMultiply,
191192
second,
192193
armstrong,
194+
getTriangleType,
195+
193196
}

test/getTriangleType.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import test from 'ava'
2+
import {getTriangleType} from '../src'
3+
4+
test('gets the type of a triangle when Equilateral', t => {
5+
const a = 10
6+
const b = 10
7+
const c = 10
8+
const expected = 'Equilateral'
9+
const actual = getTriangleType(a, b, c)
10+
t.deepEqual(actual, expected)
11+
})
12+
13+
test('gets the type of a triangle when Isosceles', t => {
14+
const a = 10
15+
const b = 20
16+
const c = 20
17+
const expected = 'Isosceles'
18+
const actual = getTriangleType(a, b, c)
19+
t.deepEqual(actual, expected)
20+
})
21+
22+
test('gets the type of a triangle when Scalene', t => {
23+
const a = 10
24+
const b = 20
25+
const c = 30
26+
const expected = 'Scalene'
27+
const actual = getTriangleType(a, b, c)
28+
t.deepEqual(actual, expected)
29+
})

0 commit comments

Comments
 (0)