diff --git a/index.html b/index.html
index 84131ea..1a5dacc 100644
--- a/index.html
+++ b/index.html
@@ -128,6 +128,9 @@
`;
- // For expression in dict
- let terms = Object.keys(expressionDict);
- for (const term of terms)
+ let Constants = ['e', "pi", 'c'];
+ let exp = cleanExpression(expression);
+ let list = [];
+ let content = "";
+ let type = "";
+ let precedence = "";
+ let commutative = true;
+ let i = 0;
+ while (i < exp.length)
{
- let coeff = expressionDict[term];
- // Compare to solution, and give correct colour
- let colour = evaluateTerm(term, coeff, SOLUTION);
- // Format coefficient correctly for display (e.g {'x', -1} -> -x, {'x', 5} -> 5x if first term, +5x if not)
- let displayCoeff = '';
- if (coeff[0] == '-')
+ if (exp[i] == '-')
{
- displayCoeff = (coeff == '-1') ? '-' : coeff;
+
+ // If not at start of expression/bracket, add + as well
+ // e.g: 5-2 -> 5+ -1 * 2
+ if
+ (
+ !(list.length == 0 ||
+ list.length > 0 &&
+ (list[list.length - 1].type == "open bracket"
+ || list[list.length - 1].type == "function"))
+ )
+ {
+ list.push({
+ content: "+",
+ type: "operator",
+ precedence: 0,
+ commutative: true,
+ leftNode: -1,
+ rightNode: -1,
+ parent: -1,
+ depth: -1
+ });
+
+ }
+ content = "-1";
+ type = "number";
+
+ i++;
}
- else if (term == terms[0])
+
+ // If number, find end of num and add whole num
+ else if (!isNaN(exp[i]))
{
- displayCoeff = (coeff == '1') ? '' : coeff;
+ let foundNumberEnd = false;
+ for (let j = i; j < exp.length; j++)
+ {
+ if (isNaN(exp[j]))
+ {
+ content = exp.slice(i, j);
+ type = "number";
+
+ i = j;
+ foundNumberEnd = true;
+ break;
+ }
+ }
+ if (foundNumberEnd == false) // If can't find any non-nums, then number extends to end of string
+ {
+ content = exp.slice(i);
+ type = "number";
+
+ i = exp.length;
+ }
}
- else
+
+ // If bracket, add to list
+ else if (['(', ')'].includes(exp[i]))
{
- displayCoeff = (coeff == '1') ? '+' : `+${coeff}`;
+ content = exp[i];
+ type = exp[i] == '(' ? "open bracket" : "close bracket";
+
+ i++;
}
- // Append to evaluation a
block with correct colour
- expressionEvaluation += `\\(${displayCoeff}${term}\\)`;
- }
- expressionEvaluation += "
";
- // Calculate number of terms missing from dict
- let missingTermsCount = calculateMissingTerms(expressionDict, SOLUTION);
- // Append