Skip to content

Commit

Permalink
📝 Make Day 15 compliant to its own spec
Browse files Browse the repository at this point in the history
Pop must takes the oldest item, not the most recent one!
  • Loading branch information
dubzzz authored Dec 20, 2024
1 parent fc25b7a commit 8a996da
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions website/blog/2024-12-15-advent-of-pbt-day-15/buggy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ export default function advent() {
return index;
},
pop: () => {
const prevLast = (last - 1 + size) % size;
const prevIndex = remapped[prevLast];
if (data[prevIndex] === undefined) {
const index = remapped[first];
if (data[index] === undefined) {
return -1;
}
data[prevIndex] = undefined;
last = prevLast;
return prevIndex;
data[index] = undefined;
first = (first + 1) % size;
return index;
},
isEmpty: () => {
return first === last;
Expand Down

0 comments on commit 8a996da

Please sign in to comment.