Skip to content

Commit

Permalink
Create mentoring.md for Triangle exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
theluckyprogrammer authored Oct 27, 2024
1 parent b899040 commit 0ca07a3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tracks/csharp/exercises/triangle/triangle/mentoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
We need to check first if the triangle is a triangle.
```
static bool IsTriangle(double a, double b, double c) => a + b > c && a + c > b && b + c > a;
```
Then, all of the methods have to invoke it as a first step and add the rest of the condition
```
public static bool IsEquilateral(double a, double b, double c) => IsTriangle(a,b,c) && a == b && b == c;
public static bool IsIsosceles(double a, double b, double c) => IsTriangle(a,b,c) && (a == b || b == c || a == c);
public static bool IsScalene(double a, double b, double c) => IsTriangle(a,b,c) && (a != b && b != c && a != c);
```
As in the example above, all of them can be one-line methods set with lambda expression,
here is a helpful part of the documentation for [lambda expression](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-operator#expression-body-definition)

You may also make a remark that lambda expression aren't only related to C#, they are also used in different languages like [javascript/typescript](https://www.tutorialspoint.com/how-to-use-lambda-expression-in-typescript#:~:text=Lambda%20expressions%2C%20commonly%20referred%20to,defining%20functions%20in%20both%20languages.)

0 comments on commit 0ca07a3

Please sign in to comment.