operations callback table in Calculator
This commit is contained in:
parent
113aa388a1
commit
38d008b050
|
@ -8,11 +8,21 @@ export default function Calculator(props){
|
||||||
const [operation,setOperation] = useState("")
|
const [operation,setOperation] = useState("")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function handleInput(content){
|
function handleInput(content){
|
||||||
|
const operations = {
|
||||||
|
"+":(a,b)=>{return a+b},
|
||||||
|
"-":(a,b)=>{return a-b},
|
||||||
|
"X":(a,b)=>{return a*b},
|
||||||
|
"/":(a,b)=>{return a/b},
|
||||||
|
}
|
||||||
|
|
||||||
if(typeof content === "number" ){
|
if(typeof content === "number" ){
|
||||||
setInput(prev=>{return prev.toString()+content.toString()})
|
setInput(prev=>{return prev.toString()+content.toString()})
|
||||||
}else{ //EXTRA CONDITION FOR DECIMAL, REGEX TO MAKE IT MAKE SENSE
|
}else{ //EXTRA CONDITION FOR DECIMAL, REGEX TO MAKE IT MAKE SENSE
|
||||||
setMemory(input)
|
setMemory(prev=>{operations[content](prev,input)})
|
||||||
setInput(0)
|
setInput(0)
|
||||||
setOperation(content)
|
setOperation(content)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue