|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <title>04 Day</title> |
| 7 | +</head> |
| 8 | + |
| 9 | +<body> |
| 10 | + <p><em>Please have a look at the JavaScript Console</em> 💪</p> |
| 11 | + <script> |
| 12 | + const inventors = [{ |
| 13 | + first: 'Albert', |
| 14 | + last: 'Einstein', |
| 15 | + year: 1879, |
| 16 | + passed: 1955 |
| 17 | + }, |
| 18 | + { |
| 19 | + first: 'Isaac', |
| 20 | + last: 'Newton', |
| 21 | + year: 1643, |
| 22 | + passed: 1727 |
| 23 | + }, |
| 24 | + { |
| 25 | + first: 'Galileo', |
| 26 | + last: 'Galilei', |
| 27 | + year: 1564, |
| 28 | + passed: 1642 |
| 29 | + }, |
| 30 | + { |
| 31 | + first: 'Marie', |
| 32 | + last: 'Curie', |
| 33 | + year: 1867, |
| 34 | + passed: 1934 |
| 35 | + }, |
| 36 | + { |
| 37 | + first: 'Johannes', |
| 38 | + last: 'Kepler', |
| 39 | + year: 1571, |
| 40 | + passed: 1630 |
| 41 | + }, |
| 42 | + { |
| 43 | + first: 'Nicolaus', |
| 44 | + last: 'Copernicus', |
| 45 | + year: 1473, |
| 46 | + passed: 1543 |
| 47 | + }, |
| 48 | + { |
| 49 | + first: 'Max', |
| 50 | + last: 'Planck', |
| 51 | + year: 1858, |
| 52 | + passed: 1947 |
| 53 | + }, |
| 54 | + ]; |
| 55 | + |
| 56 | + const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', |
| 57 | + 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', |
| 58 | + 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', |
| 59 | + 'Blair, Tony', 'Blake, William' |
| 60 | + ]; |
| 61 | + |
| 62 | + const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600)); |
| 63 | + |
| 64 | + console.table(fifteen); |
| 65 | + |
| 66 | + |
| 67 | + const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`); |
| 68 | + console.log(fullNames); |
| 69 | + |
| 70 | + |
| 71 | + const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1); |
| 72 | + console.table(ordered); |
| 73 | + |
| 74 | + const totalYears = inventors.reduce((total, inventor) => { |
| 75 | + return total + (inventor.passed - inventor.year); |
| 76 | + }, 0); |
| 77 | + |
| 78 | + console.log(totalYears); |
| 79 | + |
| 80 | + const oldest = inventors.sort(function(a, b) { |
| 81 | + const lastGuy = a.passed - a.year; |
| 82 | + const nextGuy = b.passed - b.year; |
| 83 | + return lastGuy > nextGuy ? -1 : 1; |
| 84 | + }); |
| 85 | + console.table(oldest); |
| 86 | + |
| 87 | + const alpha = people.sort((lastOne, nextOne) => { |
| 88 | + const [aLast, aFirst] = lastOne.split(', '); |
| 89 | + const [bLast, bFirst] = nextOne.split(', '); |
| 90 | + return aLast > bLast ? 1 : -1; |
| 91 | + }); |
| 92 | + console.log(alpha); |
| 93 | + |
| 94 | + const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck', 'pogostick']; |
| 95 | + |
| 96 | + const transportation = data.reduce(function(obj, item) { |
| 97 | + if (!obj[item]) { |
| 98 | + obj[item] = 0; |
| 99 | + } |
| 100 | + obj[item]++; |
| 101 | + return obj; |
| 102 | + }, {}); |
| 103 | + |
| 104 | + console.log(transportation); |
| 105 | + </script> |
| 106 | +</body> |
| 107 | + |
| 108 | +</html> |
0 commit comments