No 'Math' expression evaluator
Description:
The Math Department of your favorite college have requested us to write an expression evaluater.
While we can present them with a number of these, they were not satisfied as they really need the full power of the JavaScript Math object.
Additionally they so often use PI^2, cos(x)^2 and sin(x)^2 that they request the solution to implement these (as PI2, cos2 and sin2) Also, they have grown excessively tired of writing "Math." in front of all. So this must NOT be required!
Aside from their own secret tests, they have provided us with a number of tests that should evaluate within normal JavaScript precision limits.
Some expressions may contain variables. Values for these are handed over in a 'context' object and must be applied during evaluation. Use of the context object is optional for the user.
'expr' input will be valid mathematical expressions (maybe including variables of same format as JavaScript identifiers).
The result will always be a Number.
Example expressions are:
evaluate("2*PI2") == 19.739208802178716
evaluate("cos2(v) + sin2(v)", {v:5}) == 1 (almost)
evaluate("(a+b+c)/n", {a:3,b:4,c:5,n:6}) == 2
Similar Kata:
Stats:
Created | Jan 8, 2014 |
Published | Jan 13, 2014 |
Warriors Trained | 429 |
Total Skips | 156 |
Total Code Submissions | 1921 |
Total Times Completed | 141 |
JavaScript Completions | 141 |
Total Stars | 24 |
% of votes with a positive feedback rating | 80% of 47 |
Total "Very Satisfied" Votes | 34 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 9 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 5 kyu |