|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const people = [ |
| 4 | + { name: 'Wes', year: 1988 }, |
| 5 | + { name: 'Kait', year: 1986 }, |
| 6 | + { name: 'Irv', year: 1970 }, |
| 7 | + { name: 'Lux', year: 2015 } |
| 8 | +]; |
| 9 | + |
| 10 | +const comments = [ |
| 11 | + { text: 'Love this!', id: 523423 }, |
| 12 | + { text: 'Super good', id: 823423 }, |
| 13 | + { text: 'You are the best', id: 2039842 }, |
| 14 | + { text: 'Ramen in my fav food ever', id: 123523 }, |
| 15 | + { text: 'Nice Nice Nice!', id: 542328 } |
| 16 | +]; |
| 17 | + |
| 18 | +const isAdult = people.some(adult => new Date().getFullYear() - adult.year >= 19); |
| 19 | +console.log(isAdult); |
| 20 | + |
| 21 | +const allAdults = people.every(adult => new Date().getFullYear() - adult.year >= 19); |
| 22 | +console.log(allAdults); |
| 23 | + |
| 24 | + |
| 25 | +//Find the comment with the id of 823423 |
| 26 | +const comment = comments.find(c => c.id === 823423); |
| 27 | +console.log(comment.text); |
| 28 | + |
| 29 | +const index = comments.findIndex(c => c.id === 823423); |
| 30 | + |
| 31 | +// normal way |
| 32 | +comments.splice(index, 1); |
| 33 | +console.log(comments); |
| 34 | + |
| 35 | +//redux way ? |
| 36 | +// const newArray = [ |
| 37 | +// ...comments.slice(0, index), |
| 38 | +// ...comments.slice(index + 1) |
| 39 | +// ]; |
| 40 | +// console.log(newArray); |
0 commit comments