6 kyu
Expressive Objects
96joh_pot
Description:
Write
function evaluate(left, op, right)
that given two operands (left
and right
) and an operator (op
), will evaluate and return the result.
For example:
var left = {
'multiply': {
'add': [1, 2, 3, 4, 5],
'subtract': [5, 6, 7, 8, 9],
'multiply': [1, 2, 3, 4, 5],
'divide': [1, 2, 3, 4, 5]
}
};
// You will reduce each array based on its key. So you will start of with add(ing) [1,2,3,4,5] => 15
// then subtract(ing) [5, 6, 7, 8, 9] => -25 etc. Once all arrays have been reduced, you will perform the
// root key operation on all the reduced arrays. So in this case, you will multiply each reduced array with
// each other. The order is ALWAYS value of 'add' key first, then 'subtract', then 'multiply' and finally
// 'divide'.
var right = {
'subtract': {
'add': [1, 2, 3, 4, 5],
'subtract': [1, 2, 3, 4, 5],
'multiply': [1, 2, 3, 4, 5],
'divide': [1, 2, 3, 4, 5]
}
};
evaluate(left, 'add', right) === -467.0083333333333
Fundamentals
Similar Kata:
Stats:
Created | Oct 1, 2015 |
Published | Oct 1, 2015 |
Warriors Trained | 290 |
Total Skips | 4 |
Total Code Submissions | 812 |
Total Times Completed | 96 |
JavaScript Completions | 96 |
Total Stars | 14 |
% of votes with a positive feedback rating | 86% of 43 |
Total "Very Satisfied" Votes | 33 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 7 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |