mathsteps-experimental-fork
Version:
Step by step math solutions. Experimental Fork
24 lines (17 loc) • 696 B
JavaScript
import Node from '../node/index.js';
// Returns true if the node is a constant or can eventually be resolved to
// a constant.
// e.g. 2, 2+4, (2+4)^2 would all return true. x + 4 would return false
function resolvesToConstant(node) {
if (Node.Type.isOperator(node) || Node.Type.isFunction(node))
return node.args.every(child => resolvesToConstant(child))
else if (Node.Type.isConstant(node, true))
return true
else if (Node.Type.isSymbol(node))
return false
else if (Node.Type.isUnaryMinus(node))
return resolvesToConstant(node.args[0])
else
throw new Error(`Unsupported node type: ${node.type}`)
}
export { resolvesToConstant as default };