I cannot solve the remainingOrders problem in the Mixed Juices exercise. Could anyone please help?
Hey! Could you share your progress so far please? Where are you stuck? What have you tried so far? What ideas have you got about what to try next? Then someone will be more likely to be able to give you a helping hand
export function remainingOrders(timeLeft,orders){
while(timeLeft>0&&orders.length>0){
timeLeft-=timeToMixJuice(orders[0]);
orders.shift(); //removes first element from array
}
return orders;
}
2 Likes
Hi Rahul,
Your function does NOT consider the fact that orders could become empty while you still have timeLeft. So, please consider adding another condition to your while loop.
Yes Sir, you are right, thanks for pointing out my mistake : )
I have problems with the same exercise, but another section, support me with your comments
export function remainingOrders(timeLeft, orders ) {
let timeSpent = 0;
for (let i = 0; i < orders.length; i++) {
const preparationTime = timeToMixJuice(orders[i])
console.log('preparationTime ', preparationTime)
if (timeSpent + preparationTime <= timeLeft) {
console.log('preparo ', orders[i])
orders[i] = null;
timeSpent += preparationTime;
} else if (timeLeft - timeSpent > 0) {
console.log('preparo ', orders[i])
orders[i] = null;
timeSpent += preparationTime;
} else {
console.log('NO preparo ', orders[i])
}
console.log('timeSpent ', timeSpent)
}
return orders.filter((n) => !!n);
}