Travis build: 902

This commit is contained in:
Travis CI
2018-01-03 11:47:41 +00:00
parent d73740ba54
commit b2be168e86
3 changed files with 13 additions and 10 deletions

View File

@ -868,14 +868,15 @@ initialize2DArray(2, 2, 0); // [[0,0], [0,0]]
### 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 `step` to use a default value of `1`.
```js
const initializeArrayWithRange = (end, start = 0) =>
Array.from({ length: end + 1 - start }).map((v, i) => i + start);
const initializeArrayWithRange = (end, start = 0, step = 1) =>
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
```
<details>
@ -884,6 +885,7 @@ const initializeArrayWithRange = (end, start = 0) =>
```js
initializeArrayWithRange(5); // [0,1,2,3,4,5]
initializeArrayWithRange(7, 3); // [3,4,5,6,7]
initializeArrayWithRange(9, 0, 2); //[0,2,4,6,8]
```
</details>

View File

@ -152,10 +152,11 @@ groupBy(['one', 'two', 'three'], 'length'); // {3: ['one', 'two'], 5: ['three']}
.fill()
.map(() =&gt; Array(w).fill(val));
</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) =&gt;
Array.from({ length: end + 1 - start }).map((v, i) =&gt; i + start);
</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) =&gt;
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) =&gt; i * step + start);
</code></pre><pre><code class="language-js">initializeArrayWithRange(5); // [0,1,2,3,4,5]
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) =&gt; Array(n).fill(value);
</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) =&gt; {

View File

@ -8,7 +8,7 @@ You can omit `step` to use a default value of `1`.
```js
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