Created
December 22, 2022 17:06
-
-
Save caderek/d69b8d4b72bb54cf59ad64ec1b52a6f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const NUMBER_OF_FORMULAS = 1000; | |
| const generateName = (num) => { | |
| const charCode = (num % (122 - 96)) + 97; | |
| const count = Math.floor(num / 26); | |
| return String.fromCharCode(charCode).repeat(count + 1); | |
| }; | |
| const formulas = new Map( | |
| Array.from({ length: NUMBER_OF_FORMULAS }, (_, i) => [ | |
| generateName(i), | |
| (x, y) => x + y + i, | |
| ]) | |
| ); | |
| function calculateWithMap(formula, x, y) { | |
| let calcResult = 0; | |
| if (formula === "average") { | |
| formulas.forEach((formula) => { | |
| calcResult += formula(x, y); | |
| }); | |
| calcResult /= formulas.size; | |
| } else { | |
| const calc = formulas.get(formula); | |
| if (calc) { | |
| calcResult = calc(x, y); | |
| } | |
| } | |
| return Math.round(calcResult); | |
| } | |
| export default calculateWithMap; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment