Skip to content

Commit

Permalink
Triangles refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
zhabinka committed Jan 21, 2019
1 parent a7e032b commit 61a3abf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions javascript/triangle/triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ const typesList = [
},
];


const checker = (a, b, c) => {
const checker = (sides) => {
const [a, b, c] = sides.sort((x, y) => x - y);
const { type } = typesList.find(el => el.check(a, b, c));

if (type === 'illegal') {
throw new Error();
}
Expand All @@ -29,13 +30,11 @@ const checker = (a, b, c) => {

class Triangle {
constructor(a, b, c) {
this.sides = [a, b, c].sort((x, y) => x - y);
this.sides = [a, b, c];
}

kind() {
const [a, b, c] = this.sides;

return checker(a, b, c);
return checker(this.sides);
}
}

Expand Down

0 comments on commit 61a3abf

Please sign in to comment.