When I console.log’ed an array from my code, I got this:
In the square brackets, the array contents were correct, but when I pressed the dropdown arrow, it showed incorrect contents. I did some testing and found that the dropdown menu thing printed the final contents of the array, but I did not change the contents of the array anywhere in my code.
Here’s the code if anyone is curious
let positions = [];
let nums = [];
let pushAndGetNumAt = (a) => {
positions.push(a);
let pushElem = convertFloat(equation, a, equation.length);
if (typeof pushElem === "undefined")
return undefined;
nums.push(pushElem);
console.log(nums)
return pushElem.toString().length - 1;
};
for (let i = 0; i < equation.length; i++) {
if (equation[i] === " ")
continue;
if (sharedFunctions.isdigit(equation[i])) {
if (i > 0) {
if (charComparison.validateOperation(equation[i - 1]) === 0 || (!sharedFunctions.isdigit(equation[i - 1]) && equation[i - 1] !== 'm' && equation[i - 1] !== '.')) {
let ret = pushAndGetNumAt(i);
if (typeof ret === "undefined")
return undefined;
i += ret;
}
}
else {
let ret = pushAndGetNumAt(i);
if (typeof ret === "undefined")
return undefined;
i += ret;
}
}
else {
if (equation[i] === '-' && sharedFunctions.isdigit(equation[i + 1])) {
if (i > 0) {
if (charComparison.validateOperation(equation[i - 1]) === 0) {
equation = equation.substring(0, i) + 'm' + equation.substring(i + 1);
let ret = pushAndGetNumAt(i);
if (typeof ret === "undefined")
return undefined;
i += ret;
}
}
else {
equation = equation.substring(0, i) + 'm' + equation.substring(i + 1);
let ret = pushAndGetNumAt(i);
if (typeof ret === "undefined")
return undefined;
i += ret;
}
}
else if (charComparison.validateConstantChar(equation[i])) {
if (i > 0) {
if (!sharedFunctions.isdigit(equation[i - 1])) {
let ret = pushAndGetNumAt(i);
if (typeof ret === "undefined")
return undefined;
i += ret;
}
}
else {
let ret = pushAndGetNumAt(i);
if (typeof ret === "undefined")
return undefined;
i += ret;
}
}
}
}
positions.sort((a, b) => a - b); //Sort the positions in case there is some positions confusion
let retMap = {
"positions": positions,
"numbers": nums
};
return retMap;
in this case, nums
is the array being console.log
ed.