Author: Anush Narayanan
const cart = [“shoes”, “pant”, “kurta”]; const orderId = “12345”; const accountId = “someId001”; let walletBalance = “1000”; function createOrder(orderId) { returnnewPromise((resolve, reject) => { setTimeout(() => { console.log(`OrderId : ${orderId} Created`); resolve(orderId); }, 5000); }); } function proceedToPayment(orderId) { returnnewPromise((resolve, reject) => { setTimeout(() => { console.log(`Payment processed for Order Id: ${orderId}`); resolve(orderId); }, 1000); }); } function showOrderSummary(orderId) { returnnewPromise((resolve) => { console.log(`order summary for ${orderId} is ${cart.join(“, “)}`); resolve(orderId); }); } function updateWallet(userAccountId) { returnnewPromise((resolve) => { constcost=800; // just assume that the total cost is 800rs walletBalance-=cost; console.log(`total amount left in the wallet is : ${walletBalance}…
Hi, this is the solution for the homework question asked that is using only reduce to give the o/p of the first names of the people whose age is. < 30: const arr = [ { firstname: “Akshay”, age: 26 }, { firstname: “Donald”, age: 56 }, { firstname: “deepika”, age: 26 }, ]; const op = arr.reduce(function (acc, curr) { if (curr.age < 30) { acc.push(curr.firstname); } return acc; }, []); // we pass empty array as the inital value as accumulator and then push the firstnames whose age < 30 console.log(op); https://www.youtube.com/watch?v=zdp0zrpKzIE -> link to the video. Thanks,…
Hi all, I also figured out another way out to write the code for printing 1,2,3,4,5 in 1,2,3,4,5 seconds respectively without using let and only using var. this is regarding EP-11 | setTimeout + closures interview questions ( https://www.youtube.com/watch?v=eBTBG4nda2A&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&index=13 ). i have given the code below, kindly let me know if this could be considered as an another solution since it was giving me the correct output. function altSol(){ for (var i = 1;i<=5; i++){ setTimeout(function (i){ console.log(i); }(i),i*1000); } } altSol();
Contact Us
Subscribe to Stay Updated
Stay ahead in the world of tech with our exclusive newsletter! Subscribe now for regular updates on the latest trends, valuable coding resources, and tips to boost your frontend development skills.