Cuando calculo dígitos individuales como 4+3 o incluso 9*9, lo hace bien, pero cuando intento hacer varios dígitos, solo calcula el primer dígito de cada número. Por ejemplo, 54+28 me da 14. No estoy seguro de dónde está el error, así que aquí está mi código, excepto las cosas que sé que no son importantes:
function reducer(state, {type, payload}){ switch(type) { case ACTIONS.ADD_DIGIT: if(state.overwrite) { return { ...state, currentOperand: payload.digit, overwrite: false, } } return { ...state, previousOperand: evaluate(state), operation: payload.operation, currentOperand: null } case ACTIONS.EVALUATE: if( state.operation == null || state.currentOperand == null || state.previousOperand == null ) { return state } return { ...state, overwrite: true, previousOperand: null, operation:null, currentOperand: evaluate(state), } } } function evaluate({currentOperand, previousOperand, operation}){ const prev = parseFloat(previousOperand) const current = parseFloat(currentOperand) if (isNaN(prev) || isNaN(current)) return "" let computation = "" switch(operation) { case "+": computation = prev + current break case "-": computation = prev - current break case "*": computation = prev * current break case "÷": computation = prev / current break } return computation.toString() }