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

Commit

Permalink
feat(getTriangleType): get type of a Triangle (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolah2009 authored and Kent C. Dodds committed Feb 18, 2019
1 parent c8ee1a3 commit 8b80d3c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/getTriangleType.js
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'
)
}
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import clone from './clone'
import arrMultiply from './array-multiplier'
import second from './second'
import armstrong from './armstrong'
import getTriangleType from './getTriangleType'

export {
reverseArrayInPlace,
Expand Down Expand Up @@ -190,4 +191,6 @@ export {
arrMultiply,
second,
armstrong,
getTriangleType,

}
29 changes: 29 additions & 0 deletions test/getTriangleType.test.js
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)
})

0 comments on commit 8b80d3c

Please sign in to comment.