Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd4302c

Browse files
committed
map-filter homework added
1 parent bcf127e commit dd4302c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Week2/homework/map_filter.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
'use strict';
22

3-
const numbers = [1, 2, 3, 4];
3+
const numbers = [1, 2, 3, 4, 5, 6, 7];
44

55
// Add your code here
6+
7+
//Find the odds and assign them into a variable by using filter:
8+
9+
const oddOnes = numbers.filter(i => i % 2 != 0)
10+
11+
//Double the odds and kick out the evens:
12+
13+
const oddDoubling = oddOnes.map(i => {
14+
if (i % 2 != 0) {return i * 2;}
15+
else {return i;}
16+
})
17+
18+
console.log("Doubled lucky odds: " + oddDoubling + "\nUnlucky kicked evens: " +oddOnes);

0 commit comments

Comments
 (0)