A JS program to generate a game result based on given parameters
We can do this by three methods:
- Push an element into an array each time, then calculate the length of the array. (Naive algorithm, takes up more space)
- Simple addition based arithmetic. (Comparatively better)
- A subtraction based arithmetic. (Best one, fewer lines of code, lesser comparisons)
I have implemented the last two algorithms. The first one is a thought experiment that can be implemented very easily.