docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a calculator that allows users to define their own mathematical functions using formula notation and then use those functions in subsequent calculations. This is useful for scientific computing, financial analysis, or any application where users need to create reusable custom formulas.
/**
* A calculator that supports user-defined functions.
*/
class Calculator {
/**
* Creates a new Calculator instance.
*/
constructor() {
// IMPLEMENTATION HERE
}
/**
* Defines a custom function using formula notation (e.g., "f(x) = x^2").
*
* @param {string} functionDefinition - The function definition string
*/
defineFunction(functionDefinition) {
// IMPLEMENTATION HERE
}
/**
* Evaluates a mathematical expression, which may use previously defined functions.
*
* @param {string} expression - The expression to evaluate
* @returns {number} The result of evaluating the expression
*/
evaluate(expression) {
// IMPLEMENTATION HERE
}
}
module.exports = { Calculator };Provides mathematical expression evaluation and parsing capabilities.