////////////////**** FILTER FUNCTION*****/////////////////// const MyNum = [1,2,3,4,5,6,7,8,9,10] const mynums = MyNum .map((num) => num * 10) .map((num) => num + 1) .filter((num) => num >= 40) console.log(mynums); //////// reduce function /////////////////////// const NUM = [1, 2, 3, 4]; const mytotal = NUM.reduce(function (acc, currval) { console.log(`acc: ${acc} and currval: ${currval}`); return acc + currval; }, 0); // zero is the acc's initial value console.log(mytotal); const mytot = NUM.reduce((acc, curr) => acc+curr, 0 ) console.log(mytot); const shoppingCart = [ { itemName: "js course", price: 2999 }, { itemName: "py course", price: 999 }, { itemName: "mobile dev course", price: 5999 }, { itemName: "data science course", price: 12999 }, ] const priceToPay = shoppingCart.reduce((acc, item) => acc + item.price, 0) console.log(priceToPay);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter