mathsteps-experimental-fork
Version:
Step by step math solutions. Experimental Fork
26 lines (18 loc) • 757 B
JavaScript
;
const index = require('../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 (index.default.Type.isOperator(node) || index.default.Type.isFunction(node))
return node.args.every(child => resolvesToConstant(child))
else if (index.default.Type.isConstant(node, true))
return true
else if (index.default.Type.isSymbol(node))
return false
else if (index.default.Type.isUnaryMinus(node))
return resolvesToConstant(node.args[0])
else
throw new Error(`Unsupported node type: ${node.type}`)
}
module.exports = resolvesToConstant;