- 1

JavaScript prefix calculator

For this test we need expected to write a function that evaluates an expression written in prefix notation and returns a value For example expression: + 1 5 variables: {} result_expression: 6​​ expression: + 1 2 3 variables: {} result_expression: null expression: + 1 variables: {} result_expression: null expression: 9 variables: {} result_expression: 9 expression: * + 1 2 3 variables: {} result_expression: 9 Although negative numeric operands are invalid in expression, intermediate and final results may be negative: expression: + 6 * - 4 + 2 3 8 variables: {} result_expression: -2 Operators and operands must be separated by one or more white spaces: expression: -+1 5 3 variables: {} result_expression: null expression: + 1 2 variables: {} result_expression: 3 Expression containing variables: expression: * + 2 x y variables: { "x": 1, "y": 3 } result_expression: 9

18th Feb 2021, 5:58 AM
Mohamadreza Golbaba
Mohamadreza Golbaba - avatar
2 Antworten
+ 1
How is this evaluated as -2? + 6 * - 4 + 2 3 8
18th Feb 2021, 6:31 AM
Ipang
0
6 + ((4 - (2 + 3)) * 8) like this
18th Feb 2021, 7:04 AM
Mohamadreza Golbaba
Mohamadreza Golbaba - avatar