Skip to content

Commit 542734a

Browse files
committed
added arrow.js
1 parent f201a5f commit 542734a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

arrow.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// ES5 Version:
2+
3+
// function double(arr) {
4+
// return arr.map(function(val) {
5+
// return val * 2;
6+
// });
7+
// }
8+
9+
// Refactor with ES2015 arrow functions
10+
11+
12+
const double = arr => arr.map(val => val * 2);
13+
14+
////////////////////////////////////////////////////////////////
15+
16+
Refactor:
17+
18+
// function squareAndFindEvens(numbers){
19+
// var squares = numbers.map(function(num){
20+
// return num ** 2;
21+
// });
22+
// var evens = squares.filter(function(square){
23+
// return square % 2 === 0;
24+
// });
25+
// return evens;
26+
// }
27+
28+
const squareAndFindEvens = numbers => numbers.map(num => num ** 2).filter(square => square % 2 === 0);

0 commit comments

Comments
 (0)