|
| 1 | +const coding = ["js", "ruby", "java", "python", "cpp"] |
| 2 | + |
| 3 | +// const values= coding.forEach((item)=>{ |
| 4 | +// // console.log(item); |
| 5 | +// return item |
| 6 | +// }) |
| 7 | + |
| 8 | +// console.log(values); |
| 9 | +//forEach doesn't return any values |
| 10 | + |
| 11 | +const myNums= [1,2,3,4,5,6,7,8,9,10] |
| 12 | + |
| 13 | +// const newNums= myNums.filter((num) => num>4) |
| 14 | +// console.log(newNums); |
| 15 | + |
| 16 | +// const newNums= myNums.filter((num) => {return num>4}) |
| 17 | +// console.log(newNums); |
| 18 | +//If we use curly braces, then without return keyword nothing is returned |
| 19 | + |
| 20 | +const newNums = [] |
| 21 | + |
| 22 | +myNums.forEach((num) => { |
| 23 | + if(num>4){ |
| 24 | + newNums.push(num) |
| 25 | + } |
| 26 | +}) |
| 27 | +console.log(newNums); |
| 28 | + |
| 29 | +const books = [ |
| 30 | + { title: 'Book One', genre: 'Fiction', publish: 1981, edition: 2004 }, |
| 31 | + { title: 'Book Two', genre: 'Non-Fiction', publish: 1992, edition: 2008 }, |
| 32 | + { title: 'Book Three', genre: 'History', publish: 1999, edition: 2007 }, |
| 33 | + { title: 'Book Four', genre: 'Non-Fiction', publish: 1989, edition: 2010 }, |
| 34 | + { title: 'Book Five', genre: 'Science', publish: 2009, edition: 2014 }, |
| 35 | + { title: 'Book Six', genre: 'Fiction', publish: 1987, edition: 2010 }, |
| 36 | + { title: 'Book Seven', genre: 'History', publish: 1986, edition: 1996 }, |
| 37 | + { title: 'Book Eight', genre: 'Science', publish: 2011, edition: 2016 }, |
| 38 | + { title: 'Book Nine', genre: 'Non-Fiction', publish: 1981, edition: 1989 }, |
| 39 | + ]; |
| 40 | + |
| 41 | +let userBooks= books.filter((bk) => bk.genre==="History") |
| 42 | + |
| 43 | +userBooks= books.filter((bk) => {return bk.publish>1995 && bk.genre==="History"}) |
| 44 | + |
| 45 | +console.log(userBooks); |
0 commit comments