Challenges

Add
HARD
Attempted: 1
Completed: 1
Likes: 2

Write a function called calculate which takes an input string expression and computes the given expression and returns the values. The expression will only contain the four basic athematic operations + (addition), - (subtraction), * (multiplication), and / (division). The expression may contain brackets () to check the order of operations. By default multiplication and division take higher precedence than addition and subtraction. Unary operations will not be used (for example -2 will not be used, but 5 - 2 will be used).

Examples:

Input: 5
Output: 5
Input: 2 + 3 * 4
Output: 14
Input: (2 + 3) * 4
Output: 20