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

Skip to content

Commit 80d8155

Browse files
committed
add code for classwork on arrow functions
1 parent 313b5b7 commit 80d8155

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<link type = "text/css" href="./main.css" rel="stylesheet">
9+
</head>
10+
<body>
11+
<h1>Hello world!</h1>
12+
<script src="./main.js"></script>
13+
</body>
14+
</html>

JavaScript2/Week5/classwork-arrow-functions/main.css

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function squareMeOld(n) {
2+
return n * n;
3+
}
4+
5+
const squareMe = n => n ** 2;
6+
7+
function foo(n) {
8+
return n + 2;
9+
}
10+
11+
const foo1 = n => n + 2;
12+
13+
const numbers = [1, 2, 3, 4, 5];
14+
15+
const result = numbers
16+
.map(n => n + 2)
17+
.map(x => x * 4)
18+
.map(z => Math.sqrt(z));
19+
20+
console.log(result);
21+
22+
const interimResult1 = numbers.map(n => n + 2);
23+
console.log(interimResult1);
24+
25+
const interimResult2 = interimResult1.map(x => x * 4);
26+
console.log(interimResult2);
27+
28+
const finalResult = interimResult2.map(z => Math.sqrt(z));
29+
console.log(finalResult);
30+
31+
32+
// =>
33+
// ->
34+
// this
35+
36+
console.log(squareMe(10));
37+
console.log(squareMe(15));
38+
console.log(squareMe(5));
39+
40+
41+
const mentors = [
42+
{ name: 'Abed Sujan', subjects: ['JS', 'HTML', 'CSS', 'NODEJS'], yearOfExperience: 4 },
43+
{ name: 'Ahmed Magdy', subjects: ['JS', 'Database', 'CSS'], yearOfExperience: 1 },
44+
{ name: 'Alicia Gonzales', subjects: ['DB', 'HTML', 'NODEJS'], yearOfExperience: 8 },
45+
{ name: 'allan Thraen', subjects: ['REACT', 'HTML', 'CSS'], yearOfExperience: 3 },
46+
{ name: 'Anders Ravn', subjects: ['JS', 'HTML', 'NODEJS'], yearOfExperience: 2 },
47+
{ name: 'Daniel Fernandes', subjects: ['Database', 'HTML', 'CSS'], yearOfExperience: 9 }
48+
];
49+
50+
// Map mentors array to a new array containing number of subjects each mentor can teach
51+
// Use
52+
// 1. Arrow functions
53+
// 2. Array.map
54+
55+
56+
const subjectCountsArray = mentors.map(m => m.subjects.length);
57+
console.log(subjectCountsArray);

0 commit comments

Comments
 (0)