|
| 1 | +// console.log("hello world"); |
| 2 | + |
| 3 | +// const myNUmber = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 4 | + |
| 5 | +// const total = myNUmber.filter((item) => item > 4); |
| 6 | + |
| 7 | +// console.log(total); |
| 8 | + |
| 9 | +// const newNums = []; |
| 10 | +// newNums.forEach((num) => { |
| 11 | +// if (num > 4) { |
| 12 | +// newNums.push(num); |
| 13 | +// } |
| 14 | +// }); |
| 15 | +// console.log(newNums); |
| 16 | +//======================Filter============================= |
| 17 | +// const myNUmber = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 18 | + |
| 19 | +// const total = myNUmber.filter((item) => { |
| 20 | +// return item + 10; //filter whi array return krta he .. |
| 21 | +// }); |
| 22 | + |
| 23 | +// console.log(total); |
| 24 | +//=================MAP===================== |
| 25 | +const myNUmber = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 26 | + |
| 27 | +// const total = myNUmber.map((item) => { |
| 28 | +// return item * 10; |
| 29 | +// }); |
| 30 | +// console.log(total); // creates new array. |
| 31 | + |
| 32 | +// const total = myNUmber |
| 33 | +// .map((item) => item * 10) |
| 34 | +// .map((item) => item + 1) |
| 35 | +// .map((item) => item + 1) |
| 36 | +// .filter((item) => item >= 40); |
| 37 | +// console.log(total); // creates new array. |
| 38 | + |
| 39 | +//=====================Reduce Method ========================== |
| 40 | + |
| 41 | +const arr1 = [1, 2, 3]; |
| 42 | +// const result = arr1.reduce((acc, val) => { |
| 43 | +// console.log(`acc value is ${acc} and value is ${val}`); |
| 44 | +// return acc + val; |
| 45 | +// }, 0); //here 0 is the initial value .. |
| 46 | + |
| 47 | +// console.log(result); |
| 48 | + |
| 49 | +// const mytotal = arr.reduce((acc, val) => acc + val, 0); //shortest form |
| 50 | +// console.log(mytotal); |
| 51 | + |
| 52 | +const ShoppingCart = [ |
| 53 | + { |
| 54 | + productName: "shirt", |
| 55 | + price: 1500, |
| 56 | + }, |
| 57 | + { |
| 58 | + productName: "pent", |
| 59 | + price: 3000, |
| 60 | + }, |
| 61 | + { |
| 62 | + productName: "Tie", |
| 63 | + price: 500, |
| 64 | + }, |
| 65 | + { |
| 66 | + productName: "Coat", |
| 67 | + price: 15000, |
| 68 | + }, |
| 69 | +]; |
| 70 | + |
| 71 | +const priceToPay = ShoppingCart.reduce((acc, item) => acc + item.price, 0); |
| 72 | +console.log(`Your Total Bill Is ${priceToPay}`); |
0 commit comments