Skip to content

Commit

Permalink
use multiple return statements as recommended by review, see #398
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Mar 21, 2023
1 parent 7588187 commit 66214d3
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions js/quadrilateral/view/SideDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ export default class SideDescriber {
* "2 and three-quarter units".
*/
public getSideUnitsDescription(): NullableQuadrilateralStringType {

// REVIEW: The "multiple returns" idea will help so much here - Great!
let sideDescription: NullableQuadrilateralStringType = null;

const shapeModel = this.quadrilateralShapeModel;
const sideLength = this.side.lengthProperty.value;

Expand All @@ -151,24 +147,24 @@ export default class SideDescriber {
if ( numberOfFullUnits === 1 ) {

// "one unit"
sideDescription = oneUnitStringProperty;
return oneUnitStringProperty;
}
else {

// "3 units"
sideDescription = StringUtils.fillIn( numberOfUnitsPatternStringProperty, {
return StringUtils.fillIn( numberOfUnitsPatternStringProperty, {
numberOfUnits: numberOfFullUnits
} );
}
}
else if ( shapeModel.isInterLengthEqualToOther( remainder, QuadrilateralSide.SIDE_SEGMENT_LENGTH / 2 ) ) {
if ( numberOfFullUnits === 0 ) {
sideDescription = oneHalfUnitsStringProperty;
return oneHalfUnitsStringProperty;
}
else {

// three and a half units
sideDescription = StringUtils.fillIn( numberOfUnitsAndAHalfPatternStringProperty, {
return StringUtils.fillIn( numberOfUnitsAndAHalfPatternStringProperty, {
numberOfUnits: numberOfFullUnits
} );
}
Expand All @@ -177,12 +173,12 @@ export default class SideDescriber {
if ( numberOfFullUnits === 0 ) {

// "one quarter units"
sideDescription = oneQuarterUnitStringProperty;
return oneQuarterUnitStringProperty;
}
else {

// 2 and three-quarter units
sideDescription = StringUtils.fillIn( numberAndOneQuarterUnitsPatternStringProperty, {
return StringUtils.fillIn( numberAndOneQuarterUnitsPatternStringProperty, {
fullNumber: numberOfFullUnits
} );
}
Expand All @@ -191,12 +187,12 @@ export default class SideDescriber {
if ( numberOfFullUnits === 0 ) {

// "one quarter units"
sideDescription = threeQuarterUnitsStringProperty;
return threeQuarterUnitsStringProperty;
}
else {

// 2 and three-quarter units
sideDescription = StringUtils.fillIn( numberAndThreeQuarterUnitsPatternStringProperty, {
return StringUtils.fillIn( numberAndThreeQuarterUnitsPatternStringProperty, {
fullNumber: numberOfFullUnits
} );
}
Expand All @@ -207,23 +203,23 @@ export default class SideDescriber {
const numberOfExtraCornerUnits = numberOfQuarterUnits % 4;
if ( numberOfExtraCornerUnits === 0 ) {
if ( numberOfFullUnits === 0 ) {
sideDescription = aboutOneUnitStringProperty;
return aboutOneUnitStringProperty;
}
else {
// about 3 units (just under, currently)
sideDescription = StringUtils.fillIn( aboutNumberUnitsPatternStringProperty, {
return StringUtils.fillIn( aboutNumberUnitsPatternStringProperty, {
number: numberOfFullUnits + 1
} );
}
}
else if ( numberOfExtraCornerUnits === 2 ) {
if ( numberOfFullUnits === 0 ) {
// about one-half units
sideDescription = aboutOneHalfUnitsStringProperty;
return aboutOneHalfUnitsStringProperty;
}
else {
// about 1 and a half units
sideDescription = StringUtils.fillIn( aboutNumberAndAHalfUnitsPatternStringProperty, {
return StringUtils.fillIn( aboutNumberAndAHalfUnitsPatternStringProperty, {
number: numberOfFullUnits
} );
}
Expand All @@ -234,23 +230,21 @@ export default class SideDescriber {

// about three-quarter units
// about one-quarter units
sideDescription = StringUtils.fillIn( aboutNumberQuarterUnitsPatternStringProperty, {
return StringUtils.fillIn( aboutNumberQuarterUnitsPatternStringProperty, {
number: numberOfExtraCornerUnits
} );
}
else {

// about 2 and one quarter units
// about 3 and three-quarter units
sideDescription = StringUtils.fillIn( aboutFullNumberAndNumberQuarterUnitsPatternStringProperty, {
return StringUtils.fillIn( aboutFullNumberAndNumberQuarterUnitsPatternStringProperty, {
fullNumber: numberOfFullUnits,
number: numberOfExtraCornerUnits
} );
}
}
}

return sideDescription;
}

/**
Expand Down

0 comments on commit 66214d3

Please sign in to comment.