Merge pull request #118 from Chalarangelo/Chalarangelo-fill-array

Create fill-array.md
This commit is contained in:
Angelos Chalaris
2017-12-14 17:00:12 +02:00
committed by GitHub

10
snippets/fill-array.md Normal file
View File

@ -0,0 +1,10 @@
### Fill array
Use `Array.map()` to map values between `start` (inclusive) and `end` (exclusive) to `value`.
Omit `start` to start at the first element and/or `end` to finish at the last.
```js
const fillArray = (arr, value, start = 0, end = arr.length) =>
arr.map((v,i) => i>=start && i<end ? value : v);
// fillArray([1,2,3,4],'8',1,3) -> [1,'8','8',4]
```