Why does this LRU cache evict the most recently used key instead of the least recently used one?

I’m implementing a tiny LRU cache in JavaScript with Map insertion order, but after a get, the next put seems to evict the key I just touched. What am I misunderstanding about how to refresh recency here?

class LRU {
  constructor(limit) { this.limit = limit; this.map = new Map(); }
  get(key) {
    if (!this.map.has(key)) return -1;
    return this.map.get(key);
  }
  put(key, val) {
    this.map.set(key, val);
    if (this.map.size > this.limit) {
      const newest = [...this.map.keys()].pop();
      this.map.delete(newest);
    }
  }
}

WaffleFries

Map#set updates a value but does not move an existing key to the end, so your get never refreshes recency.

Yoshiii