Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const people = [
- {name: 'Wes', year: 1988},
- {name: 'Kait', year: 1986},
- {name: 'Irv', year: 1970},
- {name: 'Lux', year: 2015},]
- const comments = [
- {text: 'Love this!', id: 523423},
- {text: 'Super good', id: 823423},
- {text: 'You are the best', id: 2039842},
- {text: 'Ramen in my fav food ever', id: 123523},
- {text: 'Nice Nice Nice!', id: 542328}
- ];
- //some method->is at least one person 19
- const isAdult=people.some(function (person){
- const currYear=(new Date().getFullYear())
- if(currYear-person.year>=19)
- {
- return true;
- }
- })
- const isAdult2=people.some(person=>{
- const currYear=(new Date().getFullYear());
- return currYear-person.year>=19;
- })
- //console.log(isAdult2)
- //every method->is every 19
- const allAdults=people.every(function (person){
- const currYear=(new Date().getFullYear())
- if(currYear-person.year>=19)
- return true;
- })
- console.log(allAdults)
- const allAdults2=people.every(person=>
- (new Date().getFullYear())-person.year>=19);
- // console.log(allAdults2)
- //find method->first item it finds
- const comment=comments.find(function (comment){
- if(comment.id===823423)
- {
- return true;
- }
- })
- // console.log(comment)
- const comment2=comments.find(comment=>comment.id===823423);
- // console.log(comment2)
- //findIndex
- const index=comments.findIndex(comment=>comment.id===823423)
- console.log(index)
- comments.splice(index,1)
- console.table(comments)
- const newComm=[
- comments.slice(0,index),
- comments.slice(index+1)
- ]
- console.table(newComm)
Advertisement
Add Comment
Please, Sign In to add comment