mirror of
https://github.com/jbranchaud/til
synced 2026-01-05 08:08:02 +00:00
Updated JS array containing 1-to-n for ES6
Updated JS array containing 1-to-n to use arrow functions
This commit is contained in:
@@ -14,9 +14,7 @@ That gives us `0` through `9`. To get `1` through `10`, we can tweak it
|
|||||||
slightly:
|
slightly:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
> Array.apply(null, {length: 10}).map(Number.call, function(n) {
|
> Array.apply(null, {length: 10}).map(Number.call, n => { return Number(n) + 1 });
|
||||||
return Number(n) + 1;
|
|
||||||
});
|
|
||||||
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -26,9 +24,7 @@ To generalize this, we can replace `10` with `N` and then just expect that
|
|||||||
```javascript
|
```javascript
|
||||||
> var N = 10;
|
> var N = 10;
|
||||||
=> undefined
|
=> undefined
|
||||||
> Array.apply(null, {length: N}).map(Number.call, function(n) {
|
> Array.apply(null, {length: N}).map(Number.call, n => { return Number(n) + 1 });
|
||||||
return Number(n) + 1;
|
|
||||||
});
|
|
||||||
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user