Recursive Object Evaluation

ObjectsAlgorithms

Implement a function compute that processes an object containing functions and nested objects.

Function Signature:

const compute = (input, a, b, c) => {
  // Your implementation
};

Examples

Example 1
Input
const input1 = {
  A: (a, b, c) => a + b + c,
  B: (a, b, c) => a + b - c,
  C: (a, b, c) => a - b - c,
};

compute(input1, 1, 1, 1);
Output
{ a: 3, b: 1, c: -1 }
Explanation
All functions are evaluated with arguments (1, 1, 1). A = 1+1+1 = 3, B = 1+1-1 = 1, C = 1-1-1 = -1. Keys are transformed to lowercase.
Example 2
Input
const input2 = {
  A: (a, b, c) => a + b + c,
  B: (a, b, c) => a + b - c,
  C: (a, b, c) => a - b - c,
  D: {
    E: (a, b, c) => a + b + c,
  },
};

compute(input2, 1, 1, 1);
Output
{ a: 3, b: 1, c: -1, d: { e: 3 } }
Explanation
The function recursively processes nested objects. The nested object `D` is processed, and its function `E` is evaluated. All keys are transformed to lowercase.

Constraints

  • The input object can have any level of nesting
  • Functions will always receive exactly three arguments (a, b, c)
  • Non-function values should be preserved as-is
  • Keys should be transformed to lowercase

Notes

  • Use recursion to handle nested objects
  • Check if a value is a function using `typeof value === "function"`
  • Create a new object rather than modifying the input object

Hints

Read the full write-up for Recursive Object Evaluation
</>JavaScript
Loading editor…
Test Result
Run your code, or Submit to test it