|
26 | 26 |
|
27 | 27 | // Some and Every Checks
|
28 | 28 | // Array.prototype.some() // is at least one person 19 or older?
|
| 29 | + |
| 30 | + // const isAdult = people.some(function(person) { |
| 31 | + // const currentYear = (new Date()).getFullYear(); |
| 32 | + // if (currentYear - person.year >= 19) { |
| 33 | + // return true; |
| 34 | + // } |
| 35 | + // }); |
| 36 | + |
| 37 | + const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19); |
| 38 | + console.log({isAdult}); |
| 39 | + |
29 | 40 | // Array.prototype.every() // is everyone 19 or older?
|
| 41 | + const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19); |
| 42 | + console.log({allAdults}); |
30 | 43 |
|
31 | 44 | // Array.prototype.find()
|
32 | 45 | // Find is like filter, but instead returns just the one you are looking for
|
33 | 46 | // find the comment with the ID of 823423
|
34 | 47 |
|
| 48 | + // const comment = comments.find(function(comment) { |
| 49 | + // if (comment.id === 823423 ) { |
| 50 | + // return true; |
| 51 | + // } |
| 52 | + // }); |
| 53 | + |
| 54 | + // const comment = comments.find(comment => (comment.id === 823423) ? true : false); |
| 55 | + const comment = comments.find(comment => (comment.id === 823423)); |
| 56 | + |
| 57 | + console.log(comment); |
| 58 | + |
35 | 59 | // Array.prototype.findIndex()
|
36 | 60 | // Find the comment with this ID
|
37 | 61 | // delete the comment with the ID of 823423
|
| 62 | + const index = comments.findIndex(comment => (comment.id === 823423)); |
| 63 | + // console.log(index); |
| 64 | + |
| 65 | + // comments.splice(index, 1); |
| 66 | + // console.log(comments); |
| 67 | + // console.table(comments); |
| 68 | + |
| 69 | + const newComments = [ |
| 70 | + ...comments.slice(0, index), |
| 71 | + ...comments.slice(index + 1) |
| 72 | + ]; |
| 73 | + console.table(newComments); |
38 | 74 |
|
39 | 75 | </script>
|
40 | 76 | </body>
|
|
0 commit comments