|
70 | 70 | //convert the NodeList to array
|
71 | 71 | //const links = Array.from(categories.querySelectorAll('a'));
|
72 | 72 | //or better 🧑
|
73 |
| - const links = [...categories.querySelectorAll('a')]; //we need only links returns a NodeList |
| 73 | + // const links = [...categories.querySelectorAll('a')]; //we need only links returns a NodeList |
74 | 74 |
|
75 |
| - const namesWithde = links |
| 75 | + /* const namesWithde = links |
76 | 76 | .map(item => item.contentText)
|
77 | 77 | .filter(name => name.includes('de'));
|
78 |
| - console.table(namesWithde); |
| 78 | + console.table(namesWithde); */ |
79 | 79 | // 7. sort Exercise
|
80 | 80 | // Sort the people alphabetically by last name
|
81 | 81 | const sortedPeople = people.sort((a, b) => {
|
|
101 | 101 | console.log('8:', reduced)
|
102 | 102 |
|
103 | 103 |
|
| 104 | + const characters = [ |
| 105 | + { name: 'Mario', year: 1988 }, |
| 106 | + { name: 'Luigi', year: 1986 }, |
| 107 | + { name: 'Deadpool', year: 1980 }, |
| 108 | + { name: 'Lego', year: 2018 } |
| 109 | + ]; |
| 110 | + |
| 111 | + const comments = [ |
| 112 | + { text: 'Love this!', id: 523423 }, |
| 113 | + { text: 'Super good', id: 823423 }, |
| 114 | + { text: 'You are the best', id: 2039842 }, |
| 115 | + { text: 'Ramen is my fav food ever', id: 123523 }, |
| 116 | + { text: 'Nice Nice Nice!', id: 542328 } |
| 117 | + ]; |
| 118 | + |
| 119 | + // Some and Every Checks |
| 120 | + const isAdult = characters.some(person => ((new Date()).getFullYear()) - person.year >= 19); // is at least one person 19 or older? |
| 121 | + const areAdults = characters.every(person=>((new Date().getFullYear)) - person.year <= 19) // is everyone 19 or older? |
| 122 | + console.log("some :",isAdult, "every :", areAdults); |
| 123 | + // Array.prototype.find() |
| 124 | + // Find is like filter, but instead returns just the one you are looking for |
| 125 | + // find the comment with the ID of 823423 |
| 126 | + const comment = comments.find(comment => comment.id === 823423) |
| 127 | + console.log("find", comment) |
| 128 | + // Array.prototype.findIndex() |
| 129 | + // Find the comment with this ID |
| 130 | + // delete the comment with the ID of 823423 |
| 131 | + const index = comments.findIndex(comment => comment.id === 823423) |
| 132 | + //comments.splice(index,1) |
| 133 | + |
| 134 | + const newComments = [ |
| 135 | + ...comments.slice(0,index), |
| 136 | + ...comments.slice(index+1) |
| 137 | + ]; |
| 138 | + console.table(newComments); |
| 139 | + |
104 | 140 | </script>
|
105 | 141 | </body>
|
106 | 142 |
|
|
0 commit comments