const handleInput = (e) => {
let val = e.target.textContent;
setCalc((calc.input = calc.input.replace(/\.+/g, ".")));
setCalc((calc.input = calc.input.replace(
/(\d+)(\.)(\d+)(\.)(\d+)/,
(p1, p2, p3, p4, p5, p6) => {
let arr = [p2, p3, p4, p6];
return arr.join("");
}
))
);
console.log(calc.input);
if (calc.input === "0") {
setCalc((calc.input = ""));
} else if (calc.input.match(/(^0)\1{2,}/)) {
setCalc(calc.input.replace(/(^0)\1{2,}/g, "0"));
}
setCalc({ input: calc.input + val });
};
I use the replace function with regex to convert the user input into the correct format before the calculation happens.
I’m getting the right results so i don’t understand why the test is not passing.