I have an array called userInput
that I am pushing my input to eventually perform an eval() calculation on.
I am adding the decimal function but need to test if a number already has a decimal in my array to avoid something like 3.00.00.00.
My current function
function addPeriod() {
if((inputArray.length == 0) || inputArray[inputArray.length -1] == '.') {
//do nothing
} else {
inputArray.push('.');
console.log(inputArray);
screenText.append('.');
}
}
The way my current userInput
array looks now during operation once I use userInput.join('')
is something like 3 + 2.00 / 1
etc... I know I need to use a regex method but not sure of the pattern that would eliminate the unwanted decimal occurrence. Thanks for the help.