Skip to content

Commit

Permalink
refactor(intg): move clearing methods above
Browse files Browse the repository at this point in the history
`appendToEntryScreen` will use one of these methods
  • Loading branch information
lemredd committed Dec 27, 2022
1 parent f4f320e commit 445deb0
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/components/CalculatorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,35 @@ const expressionToDisplay = computed(() => {
})
const hasEvaluatedResult = computed(() => previousResult.value === entry.value)
function popOneDigit() {
if (entry.value.length > 1) {
const entryDigits = Array.from(entry.value)
entryDigits.pop()
entry.value = entryDigits.join("")
} else entry.value = "0"
}
function clearEntryScreen() {
entry.value = "0"
}
function clearAll() {
entry.value = "0"
leftEntry.value = 0
rightEntry.value = 0
operation.value = null
evaluation.value = null
previousResult.value = "0"
}
function alterEntrySign() {
if (Number(entry.value) !== 0) {
const negatedEntry = Number(entry.value) * -1
entry.value = String(negatedEntry)
}
}
function appendDecimal() {
if (entry.value.includes(".")) entry.value = entry.value.replace(".", "")
entry.value += "."
}
function appendToEntryScreen(valueToAppend: Entries) {
if (valueToAppend === ".") appendDecimal()
else if (isEntryValueEmpty.value || mustResetOnNextEntry.value) entry.value = String(valueToAppend)
Expand Down Expand Up @@ -161,25 +178,6 @@ function setEvaluationValue(newEvaluation: Evaluations) {
evaluateExpression(newEvaluation)
evaluation.value = newEvaluation
}
function popOneDigit() {
if (entry.value.length > 1) {
const entryDigits = Array.from(entry.value)
entryDigits.pop()
entry.value = entryDigits.join("")
} else entry.value = "0"
}
function clearEntryScreen() {
entry.value = "0"
}
function clearAll() {
entry.value = "0"
leftEntry.value = 0
rightEntry.value = 0
operation.value = null
evaluation.value = null
previousResult.value = "0"
}
</script>

<template>
Expand Down

0 comments on commit 445deb0

Please sign in to comment.