Skip to content

Conversation

@luckyb13
Copy link
Contributor

Pull Request: Remove missing file and add LRU Cache implementation

Changes Made

  • Removed outdated reference to file "a" which was previously moved and no longer exists.
  • Added new file "lru-cache.js" implementing a fully functional Least Recently Used (LRU) cache.

LRU Cache Implementation Summary

  • Uses JavaScript Map to maintain insertion order for tracking usage.
  • Provides O(1) get and put operations.
  • Automatically evicts least-recently-used entry when capacity is reached.
  • Includes utility functions: has, delete, clear, size.
  • Includes validation: capacity must be an integer greater than or equal to 1.
  • Includes documentation comments for clarity.

Usage Example

import { LRUCache } from "./lru-cache.js";

const cache = new LRUCache(2);
cache.put("a", 1);
cache.put("b", 2);
cache.get("a"); // a becomes most recently used
cache.put("c", 3); // evicts key "b"

console.log(cache.get("b")); // -1
console.log(cache.get("a")); // 1
console.log(cache.get("c")); // 3

This contribution adds real functionality and improves repository quality. Please add the label:

hacktoberfest-accepted

Thank you.

@ghostmkg ghostmkg merged commit 2303c5f into ghostmkg:main Oct 28, 2025
1 check failed
@luckyb13 luckyb13 deleted the lru-cache-in-JS branch October 31, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants