Commit 746023e1 by 李楚霏

task--5 提炼函数step1

parent 11022629
...@@ -19,15 +19,15 @@ export class Length { ...@@ -19,15 +19,15 @@ export class Length {
let unitLength = this let unitLength = this
if (this.unit === Constants.Constants.YARD) { if (this.unit === Constants.Constants.YARD) {
if (unitNode === Constants.Constants.FOOT) { if (unitNode === Constants.Constants.FOOT) {
unitLength = new Length(this.value * 3, unitNode) unitLength = new Length(this.multipleValue(3), unitNode)
} else if (unitNode === Constants.Constants.INCH) { } else if (unitNode === Constants.Constants.INCH) {
unitLength = new Length(this.value * 36, unitNode) unitLength = new Length(this.multipleValue(36), unitNode)
} }
} }
if (this.unit === Constants.Constants.INCH) { if (this.unit === Constants.Constants.INCH) {
if (unitNode === Constants.Constants.YARD) { if (unitNode === Constants.Constants.YARD) {
unitLength = new Length(this.value / 36, unitNode) unitLength = new Length(this.divisionValue(36), unitNode)
} else if (unitNode === Constants.Constants.FOOT) { } else if (unitNode === Constants.Constants.FOOT) {
unitLength = new Length(this.value / 12, unitNode) unitLength = new Length(this.value / 12, unitNode)
} }
...@@ -35,12 +35,20 @@ export class Length { ...@@ -35,12 +35,20 @@ export class Length {
if (this.unit === Constants.Constants.FOOT) { if (this.unit === Constants.Constants.FOOT) {
if (unitNode === Constants.Constants.YARD) { if (unitNode === Constants.Constants.YARD) {
unitLength = new Length(this.value / 3, unitNode) unitLength = new Length(this.divisionValue(3), unitNode)
} else if (unitNode === Constants.Constants.INCH) { } else if (unitNode === Constants.Constants.INCH) {
unitLength = new Length(this.value * 12, unitNode) unitLength = new Length(this.multipleValue(12), unitNode)
} }
} }
return unitLength return unitLength
} }
divisionValue(conversion_Target_Unit_Value) {
return this.value / conversion_Target_Unit_Value
}
multipleValue(conversion_Target_Unit_Value) {
return this.value * conversion_Target_Unit_Value
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment