6 kyu

Expressive Objects

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

Stats:

CreatedOct 1, 2015
PublishedOct 1, 2015
Warriors Trained290
Total Skips4
Total Code Submissions812
Total Times Completed96
JavaScript Completions96
Total Stars14
% of votes with a positive feedback rating86% of 43
Total "Very Satisfied" Votes33
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes2
Total Rank Assessments7
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • joh_pot Avatar
  • smile67 Avatar
Ad