Skip to content

Commit

Permalink
use else if instead of null check, and multiple return statements as …
Browse files Browse the repository at this point in the history
…recommended by review, see #398
  • Loading branch information
jessegreenberg committed Mar 21, 2023
1 parent 66214d3 commit 59b5a74
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions js/quadrilateral/view/SideDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,33 +331,32 @@ export default class SideDescriber {
* "SideAB is much longer than sideCD."
*/
private getLengthComparisonDescription( otherSide: QuadrilateralSide ): NullableQuadrilateralStringType {
let description: NullableQuadrilateralStringType = null;

const shapeModel = this.quadrilateralShapeModel;

const length1 = this.side.lengthProperty.value;
const length2 = otherSide.lengthProperty.value;

if ( shapeModel.isInterLengthEqualToOther( length1, length2 ) ) {
description = equalToStringProperty;
return equalToStringProperty;
}
else if ( shapeModel.isInterLengthEqualToOther( length1, length2 * 2 ) ) {
description = twiceAsLongAsStringProperty;
return twiceAsLongAsStringProperty;
}
else if ( shapeModel.isInterLengthEqualToOther( length1, length2 / 2 ) ) {
description = halfAsLongAsStringProperty;
return halfAsLongAsStringProperty;
}

// REVIEW - use else if here and multiple return lines as suggested
const lengthRatio = length1 / length2;
if ( description === null ) {
else {
let description: NullableQuadrilateralStringType = null;
const lengthRatio = length1 / length2;
LENGTH_COMPARISON_DESCRIPTION_MAP.forEach( ( value, key ) => {
if ( key.contains( lengthRatio ) ) {
description = value;
}
} );

assert && assert( description, 'No description found for length ratio' );
return description;
}
return description;
}
}

Expand Down

0 comments on commit 59b5a74

Please sign in to comment.