Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})