docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
A calculator application that maintains state across multiple evaluations, allowing users to define variables and functions that persist between calculations.
/**
* Creates a new calculator instance with persistent state.
*/
class Calculator {
/**
* Evaluates a mathematical expression or assignment.
* Supports variable assignments (x = 5), function definitions (f(x) = x^2),
* and mathematical expressions.
*
* @param {string} expression - The expression to evaluate
* @returns {number|undefined} The result of the evaluation, or undefined for assignments
*/
evaluate(expression) {
// IMPLEMENTATION HERE
}
/**
* Clears all stored variables and functions from the calculator state.
*/
clear() {
// IMPLEMENTATION HERE
}
/**
* Retrieves the value of a stored variable.
*
* @param {string} name - The name of the variable
* @returns {*} The value of the variable
*/
get(name) {
// IMPLEMENTATION HERE
}
}
module.exports = { Calculator };Provides mathematical computation and expression parsing support.