|
| 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