|
32 | 32 | // } |
33 | 33 | // }); |
34 | 34 |
|
35 | | - const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19); |
| 35 | + const isAdult = people.some(function(person) { |
| 36 | + const currentYear = (new Date()).getFullYear(); |
| 37 | + if(currentYear - person.year >=19){ |
| 38 | + return true; |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + //const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19); |
36 | 43 |
|
37 | 44 | console.log({isAdult}); |
38 | 45 | // Array.prototype.every() // is everyone 19? |
39 | 46 |
|
40 | | - const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19); |
41 | | - console.log({allAdults}); |
| 47 | + // const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19); |
| 48 | + // console.log({allAdults}); |
| 49 | + |
| 50 | + const allAdults = people.every(function(person) { |
| 51 | + const currentYear = (new Date()).getFullYear(); |
| 52 | + if(currentYear - person.year >=19){ |
| 53 | + return true; |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + console.log({allAdults}); |
42 | 58 |
|
43 | 59 | // Array.prototype.find() |
44 | 60 | // Find is like filter, but instead returns just the one you are looking for |
45 | 61 | // find the comment with the ID of 823423 |
46 | 62 |
|
47 | | - |
48 | | - const comment = comments.find(comment => comment.id === 823423); |
| 63 | + const comment = comments.find(function(comment){ |
| 64 | + return comment.id === 823423; |
| 65 | + }); |
49 | 66 |
|
50 | 67 | console.log(comment); |
51 | 68 |
|
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + // const comment = comments.find(comment => comment.id === 823423); |
| 73 | + |
| 74 | + // console.log(comment); |
| 75 | + |
52 | 76 | // Array.prototype.findIndex() |
53 | 77 | // Find the comment with this ID |
54 | 78 | // delete the comment with the ID of 823423 |
55 | | - const index = comments.findIndex(comment => comment.id === 823423); |
56 | | - console.log(index); |
| 79 | + // const index = comments.findIndex(comment => comment.id === 823423); |
| 80 | + // console.log(index); |
57 | 81 |
|
58 | 82 | // comments.splice(index, 1); |
59 | 83 |
|
60 | | - const newComments = [ |
61 | | - ...comments.slice(0, index), |
62 | | - ...comments.slice(index + 1) |
63 | | - ]; |
| 84 | + // const newComments = [ |
| 85 | + // ...comments.slice(0, index), |
| 86 | + // ...comments.slice(index + 1) |
| 87 | + // ]; |
| 88 | + |
| 89 | + const index = comments.findIndex(function(comment) { |
| 90 | + return comment.id === 823423; |
| 91 | + }); |
| 92 | + |
| 93 | + console.log(index); |
| 94 | + |
| 95 | + const newComments = comments.splice(index,1); |
| 96 | + |
| 97 | + console.table(newComments); |
64 | 98 |
|
65 | 99 | </script> |
66 | 100 | </body> |
|
0 commit comments