-
Notifications
You must be signed in to change notification settings - Fork 0
/
findTheCalculationType.js
23 lines (17 loc) · 1.01 KB
/
findTheCalculationType.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// You have to create a function calcType, which receives 3 arguments: 2 numbers, and the result of an unknown operation performed on them (also a number).
// Based on those 3 values you have to return a string, that describes which operation was used to get the given result.
// The possible return strings are: "addition", "subtraction", "multiplication", "division".
// Example:
// calcType(1, 2, 3) --> 1 ? 2 = 3 --> "addition"
// Notes
// In case of division you should expect that the result of the operation is obtained by using / operator on the input values - no manual data type conversion or rounding should be performed.
// Cases with just one possible answers are generated.
// Only valid arguments will be passed to the function.
// Only valid arguments will be passed to the function!
function calcType(a, b, res) {
if (res === a + b) return "addition";
if (res === a - b) return "subtraction";
if (res === a * b) return "multiplication";
if (res === a / b) return "division";
return "invalid";
}