Travis build: 907
This commit is contained in:
27
README.md
27
README.md
@ -288,6 +288,7 @@
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`geometricProgression`](#geometricprogression)
|
||||
* [`maxN`](#maxn)
|
||||
* [`minN`](#minn)
|
||||
|
||||
@ -5098,6 +5099,32 @@ yesNo('Foo', true); // true
|
||||
---
|
||||
## _Uncategorized_
|
||||
|
||||
### 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`.
|
||||
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`.
|
||||
|
||||
```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
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
geometricProgression(256); // [1, 2, 4, 8, 16, 32, 64, 128, 256]
|
||||
geometricProgression(256, 3); //[3, 6, 12, 24, 48, 96, 192]
|
||||
geometricProgression(256, 1, 4); //[1, 4, 16, 64, 256]
|
||||
geometricProgression(256, 2, 1); //Gives error
|
||||
```
|
||||
|
||||
<br>[⬆ back to top](#table-of-contents)
|
||||
|
||||
|
||||
### maxN
|
||||
|
||||
Returns the `n` maximum elements from the provided array. If `n` is greater than or equal to the provided array's length than return the original array(sorted in descending order).
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -9,7 +9,9 @@ Omit the third argument, `step`, to use a default value of `2`.
|
||||
|
||||
```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)) )
|
||||
Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1 }).map(
|
||||
(v, i) => start * step ** i
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
@ -49,6 +49,7 @@ flip:adapter
|
||||
fromCamelCase:string
|
||||
functionName:function
|
||||
gcd:math
|
||||
geometricProgression:uncategorized
|
||||
getDaysDiffBetweenDates:date
|
||||
getScrollPosition:browser
|
||||
getStyle:browser
|
||||
|
||||
Reference in New Issue
Block a user