| Conditions | 19 |
| Total Lines | 54 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like helper.ts ➔ sortRankings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import { RankingDataTeamObject } from "../Types/Ranking" |
||
| 26 | |||
| 27 | export function sortRankings(a: RankingDataTeamObject, b: RankingDataTeamObject) { |
||
| 28 | // Rank lager: A stijgt in sortering. |
||
| 29 | if (a.rank < b.rank) { |
||
| 30 | return -1 |
||
| 31 | } |
||
| 32 | if (a.rank > b.rank) { |
||
| 33 | return 1 |
||
| 34 | } |
||
| 35 | // Aantal overwinningen hoger: A stijgt in sortering. |
||
| 36 | if (a.wins > b.wins) { |
||
| 37 | return -1 |
||
| 38 | } |
||
| 39 | if (a.wins < b.wins) { |
||
| 40 | return 1 |
||
| 41 | } |
||
| 42 | // Doelpuntensaldo beter: A stijgt in sortering. |
||
| 43 | if (a.goalsScored - a.goalsConceded > b.goalsScored - b.goalsConceded) { |
||
| 44 | return -1 |
||
| 45 | } |
||
| 46 | if (a.goalsScored - a.goalsConceded < b.goalsScored - b.goalsConceded) { |
||
| 47 | return 1 |
||
| 48 | } |
||
| 49 | // Aantal gemaakte doelpunten hoger: A stijgt in sortering. |
||
| 50 | if (a.goalsScored > b.goalsScored) { |
||
| 51 | return -1 |
||
| 52 | } |
||
| 53 | if (a.goalsScored < b.goalsScored) { |
||
| 54 | return 1 |
||
| 55 | } |
||
| 56 | // Aantal uitoverwinningen hoger: A stijgt in sortering. |
||
| 57 | if (a.winsAway > b.winsAway) { |
||
| 58 | return -1 |
||
| 59 | } |
||
| 60 | if (a.winsAway < b.winsAway) { |
||
| 61 | return 1 |
||
| 62 | } |
||
| 63 | // Doelpuntensaldo op verplaatsing beter: A stijgt in sortering. |
||
| 64 | if (a.goalsScoredAway - a.goalsConcededAway > b.goalsScoredAway - b.goalsConcededAway) { |
||
| 65 | return -1 |
||
| 66 | } |
||
| 67 | if (a.goalsScoredAway - a.goalsConcededAway < b.goalsScoredAway - b.goalsConcededAway) { |
||
| 68 | return 1 |
||
| 69 | } |
||
| 70 | // Aantal gemaakte doelpunten op verplaatsing hoger: A stijgt in sortering. |
||
| 71 | if (a.goalsScoredAway > b.goalsScoredAway) { |
||
| 72 | return -1 |
||
| 73 | } |
||
| 74 | if (a.goalsScoredAway < b.goalsScoredAway) { |
||
| 75 | return 1 |
||
| 76 | } |
||
| 77 | |||
| 78 | return a.team?.club?.localName.localeCompare(b.team?.club?.localName) |
||
| 79 | } |
||
| 80 | |||
| 123 |