Travis build: 902
This commit is contained in:
12
README.md
12
README.md
@ -868,14 +868,15 @@ initialize2DArray(2, 2, 0); // [[0,0], [0,0]]
|
|||||||
|
|
||||||
### initializeArrayWithRange
|
### initializeArrayWithRange
|
||||||
|
|
||||||
Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive.
|
Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive with there common difference `step`.
|
||||||
|
|
||||||
Use `Array((end + 1) - start)` to create an array of the desired length, `Array.map()` to fill with the desired values in a range.
|
Use `Array(Math.ceil((end+1-start)/step)` to create an array of the desired length(the amounts of elements is equal to `(end-start)/step` or `(end+1-start)/step` for inclusive end), `Array.map()` to fill with the desired values in a range.
|
||||||
You can omit `start` to use a default value of `0`.
|
You can omit `start` to use a default value of `0`.
|
||||||
|
You can omit `step` to use a default value of `1`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const initializeArrayWithRange = (end, start = 0) =>
|
const initializeArrayWithRange = (end, start = 0, step = 1) =>
|
||||||
Array.from({ length: end + 1 - start }).map((v, i) => i + start);
|
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -884,6 +885,7 @@ const initializeArrayWithRange = (end, start = 0) =>
|
|||||||
```js
|
```js
|
||||||
initializeArrayWithRange(5); // [0,1,2,3,4,5]
|
initializeArrayWithRange(5); // [0,1,2,3,4,5]
|
||||||
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
|
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
|
||||||
|
initializeArrayWithRange(9, 0, 2); //[0,2,4,6,8]
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@ -152,10 +152,11 @@ groupBy(['one', 'two', 'three'], 'length'); // {3: ['one', 'two'], 5: ['three']}
|
|||||||
.fill()
|
.fill()
|
||||||
.map(() => Array(w).fill(val));
|
.map(() => Array(w).fill(val));
|
||||||
</code></pre><pre><code class="language-js">initialize2DArray(2, 2, 0); // [[0,0], [0,0]]
|
</code></pre><pre><code class="language-js">initialize2DArray(2, 2, 0); // [[0,0], [0,0]]
|
||||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="initializearraywithrange">initializeArrayWithRange</h3></div><div class="section double-padded"><p>Initializes an array containing the numbers in the specified range where <code>start</code> and <code>end</code> are inclusive.</p><p>Use <code>Array((end + 1) - start)</code> to create an array of the desired length, <code>Array.map()</code> to fill with the desired values in a range. You can omit <code>start</code> to use a default value of <code>0</code>.</p><pre><code class="language-js">const initializeArrayWithRange = (end, start = 0) =>
|
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="initializearraywithrange">initializeArrayWithRange</h3></div><div class="section double-padded"><p>Initializes an array containing the numbers in the specified range where <code>start</code> and <code>end</code> are inclusive with there common difference <code>step</code>.</p><p>Use <code>Array(Math.ceil((end+1-start)/step)</code> to create an array of the desired length(the amounts of elements is equal to <code>(end-start)/step</code> or <code>(end+1-start)/step</code> for inclusive end), <code>Array.map()</code> to fill with the desired values in a range. You can omit <code>start</code> to use a default value of <code>0</code>. You can omit <code>step</code> to use a default value of <code>1</code>.</p><pre><code class="language-js">const initializeArrayWithRange = (end, start = 0, step = 1) =>
|
||||||
Array.from({ length: end + 1 - start }).map((v, i) => i + start);
|
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
||||||
</code></pre><pre><code class="language-js">initializeArrayWithRange(5); // [0,1,2,3,4,5]
|
</code></pre><pre><code class="language-js">initializeArrayWithRange(5); // [0,1,2,3,4,5]
|
||||||
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
|
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
|
||||||
|
initializeArrayWithRange(9, 0, 2); //[0,2,4,6,8]
|
||||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="initializearraywithvalues">initializeArrayWithValues</h3></div><div class="section double-padded"><p>Initializes and fills an array with the specified values.</p><p>Use <code>Array(n)</code> to create an array of the desired length, <code>fill(v)</code> to fill it with the desired values. You can omit <code>value</code> to use a default value of <code>0</code>.</p><pre><code class="language-js">const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="initializearraywithvalues">initializeArrayWithValues</h3></div><div class="section double-padded"><p>Initializes and fills an array with the specified values.</p><p>Use <code>Array(n)</code> to create an array of the desired length, <code>fill(v)</code> to fill it with the desired values. You can omit <code>value</code> to use a default value of <code>0</code>.</p><pre><code class="language-js">const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
|
||||||
</code></pre><pre><code class="language-js">initializeArrayWithValues(5, 2); // [2,2,2,2,2]
|
</code></pre><pre><code class="language-js">initializeArrayWithValues(5, 2); // [2,2,2,2,2]
|
||||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="intersection">intersection</h3></div><div class="section double-padded"><p>Returns a list of elements that exist in both arrays.</p><p>Create a <code>Set</code> from <code>b</code>, then use <code>Array.filter()</code> on <code>a</code> to only keep values contained in <code>b</code>.</p><pre><code class="language-js">const intersection = (a, b) => {
|
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="intersection">intersection</h3></div><div class="section double-padded"><p>Returns a list of elements that exist in both arrays.</p><p>Create a <code>Set</code> from <code>b</code>, then use <code>Array.filter()</code> on <code>a</code> to only keep values contained in <code>b</code>.</p><pre><code class="language-js">const intersection = (a, b) => {
|
||||||
|
|||||||
@ -7,12 +7,12 @@ You can omit `start` to use a default value of `0`.
|
|||||||
You can omit `step` to use a default value of `1`.
|
You can omit `step` to use a default value of `1`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const initializeArrayWithRange = (end, start = 0,step = 1) =>
|
const initializeArrayWithRange = (end, start = 0, step = 1) =>
|
||||||
Array.from({length:Math.ceil((end + 1 - start)/step)}).map((v, i) => (i * step) + start);
|
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
initializeArrayWithRange(5); // [0,1,2,3,4,5]
|
initializeArrayWithRange(5); // [0,1,2,3,4,5]
|
||||||
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
|
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
|
||||||
initializeArrayWithRange(9,0,2); //[0,2,4,6,8]
|
initializeArrayWithRange(9, 0, 2); //[0,2,4,6,8]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user