-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrows.js
33 lines (27 loc) · 927 Bytes
/
arrows.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
// function double(arr) {
// return arr.map(function (val) {
// return val * 2;
// });
// }
/*
## **ES2015 Arrow Functions Shorthand**
Refactor the above code to use two arrow functions. Turn it into a one-liner. */
const double = (arr) => arr.map(n => n * 2)
// Refactor the following function to use arrow functions:
// Replace ALL functions with arrow functions:
// function squareAndFindEvens(numbers) {
// var squares = numbers.map(function (num) {
// return num ** 2;
// });
// var evens = squares.filter(function (square) {
// return square % 2 === 0;
// });
// return evens;
// }
const squareAndFindEvens = (numbers) => {
let squares = numbers.map(n => n ** 2)
let evens = squares.filter(s => s % 2 === 0)
return evens;
}
// console.log(squareAndFindEvens(numbers));