Skip to content

Commit

Permalink
refactor: removing some duplicities
Browse files Browse the repository at this point in the history
  • Loading branch information
Farenheith committed Apr 20, 2023
1 parent ee49dfc commit 2383a06
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/recipes/aggregate-recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ class Context {
defaultId() {
return (this.customIds[this.id++] ??= Symbol(this.id));
}
getModMultiplyId(id: any) {
return typeof id === 'symbol'
? id
: (this.modMultiplySymbols[id] ??= Symbol(id));
}
getModSumId(id: any) {
return typeof id === 'symbol'
? id
: (this.modSumSymbols[id] ??= Symbol(id));
getId(id: any, prop: 'modMultiplySymbols' | 'modSumSymbols') {
return typeof id === 'symbol' ? id : (this[prop][id] ??= Symbol(id));
}
}

Expand Down Expand Up @@ -87,7 +80,7 @@ class Aggregations {
modSum(value: number, mod: number, id = this[contextSymbol].defaultId()) {
const context = (this[contextSymbol].modSumInternal ??= {});
return (context[id] =
this.sum(value, this[contextSymbol].getModSumId(id)) % mod);
this.sum(value, this[contextSymbol].getId(id, 'modSumSymbols')) % mod);
}
modMultiply(
value: number,
Expand All @@ -96,7 +89,10 @@ class Aggregations {
) {
const context = (this[contextSymbol].modMultiplyInternal ??= {});
return (context[id] =
this.multiply(value, this[contextSymbol].getModMultiplyId(id)) % mod);
this.multiply(
value,
this[contextSymbol].getId(id, 'modMultiplySymbols'),
) % mod);
}
}

Expand Down

0 comments on commit 2383a06

Please sign in to comment.