I’m baffled. I’ve checked dozens of times with various logs but I can’t imagine why this While loop stops early. The conditions are still true when the loop stops but it refuses to keep going.
export function limesToCut(wedgesNeeded, limes) {
let wedgesCut = 0;
let limesCut = 0;
if (limes.length === 0) {return 0};
if (wedgesNeeded === 0) {limesCut = 0; return limesCut};
if (limesCut >= limes.length) {return limes.length};
while ((limesCut < limes.length) && (wedgesCut < wedgesNeeded)) {
let currentLime = limes.shift();
switch (currentLime) {
case 'small':
wedgesCut += 6;
limesCut++;
break;
case 'medium':
wedgesCut += 8;
limesCut++;
break;
case 'large':
wedgesCut += 10;
limesCut++;
break;
}
console.log(currentLime);
console.log('Limes cut: ' + limesCut);
console.log('Wedges cut: ' + wedgesCut);
}
return limesCut;
}