Update geometricProgression.md
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
### geometricProgression
|
||||
|
||||
Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive and the ratio between two terms is `step`.
|
||||
Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive and the ratio between two terms is `step`.
|
||||
Returns an error if `step` equals `1`.
|
||||
|
||||
Use `Array.from()`, `Math.log()` and `Math.floor()` to create an array of the desired length, `Array.map()` to fill with the desired values in a range.
|
||||
Omit the second argument, `start`, to use a default value of `1`.
|
||||
Omit the third argument, `step`, to use a default value of `2`.
|
||||
|
||||
Use Array(Math.floor(Math.log(end/start)/Math.log(step))+1) to create an array of the desired length, Array.map() to fill with the desired values in a range.
|
||||
You can omit `start` to use a default value of 1.
|
||||
You can omit `step` to use a default value of 2.
|
||||
Returns a error when you try to use `step = 1`
|
||||
``` js
|
||||
const geometricProgression = (end, start = 1,step = 2) =>
|
||||
Array.from({ length:Math.floor(Math.log(end/start)/Math.log(step))+1}).map((v, i) => start * (step ** (i)) )
|
||||
|
||||
Reference in New Issue
Block a user