$ show TheAlgorithms/JavaScript
TheAlgorithms/JavaScript is an extensive open-source collection of over 700 algorithm and data structure implementations in JavaScript, designed for educational purposes. It covers a wide range of categories including sorting, searching, dynamic programming, graph algorithms, cryptography, math, string manipulation, and more. Each algorithm is implemented as a standalone module with corresponding tests, following ES module syntax. While primarily a learning resource, several components like caching classes (LRU, LFU), memoization utilities, and classic data structures (binary heap, AVL tree, Trie) demonstrate high-quality, reusable patterns. The repository employs CI/CD, linting, and automatic directory updates, ensuring code consistency. However, some modules exhibit minor issues such as DOM dependencies in Node context and duplicate implementations, reflecting the community-contributed nature of the project.
The LLM identified 4 files worth highlighting for reuse:
Implements a Least Frequently Used cache using a frequency map of doubly linked lists. Puts and gets operate in O(1) average time. Well-encapsulated with private fields (#capacity, #size, #minFrequency, etc.). Reusable in any JavaScript project needing cache eviction policies.
Generic memoization utility that accepts any cache constructor (e.g., Map, LRUCache, LFUCache) and returns a decorated function. Demonstrates an elegant strategy pattern for caching. Fully reusable and framework-agnostic.
A priority queue implemented as a binary heap that supports custom comparator functions and keyed operations (has, increasePriority). Uses a hashmap for O(1) key lookup. Well-structured and suitable for graph algorithms like Dijkstra.
Self-balancing binary search tree implementing AVL rotations (left, right, left-right, right-left). Maintains height property for balance factor calculation. Exposes standard BST operations (insert, remove, find, in-order traversal) with O(log n) time complexity. Production-quality implementation.