A developer documenting their DSA (data structures and algorithms) revision has rebuilt a phonebook demo app, swapping array-based linear search for HashMap lookups. The project, hosted on Netlify, illustrates a pattern enterprise teams know well: working code isn't always scalable code.
What Changed
The original implementation stored contacts in a JavaScript array and used .find() to locate entries - O(n) time complexity. Each search potentially scans the entire list. The refactor uses JavaScript's native object as a HashMap, enabling O(1) constant-time lookups by username key.
// Before: O(n) linear search
const result = userArray.find(contact => contact.userName === "Oscar");
// After: O(1) HashMap lookup
const number = contactMap["Oscar"];
The developer added case-insensitive search by storing lowercase keys while preserving original names - a practical touch.
Why This Matters
For small datasets (under 1,000 entries), linear search performs adequately. The trade-off shifts at scale. A contact list with 100,000 entries hits worst-case O(100,000) time with array search versus consistent O(1) with hashing.
Enterprise systems face this pattern constantly: customer lookups, session management, cache implementations. The HashMap pattern (whether JavaScript's Map object, Redis, or in-memory stores) handles key-value retrieval at scale.
The Fine Print
JavaScript objects work as hashmaps for string keys but lack Map's advantages: support for non-string keys, built-in size tracking, and guaranteed insertion order. For production contact systems, native Map or established libraries handle collision resolution and rehashing that custom implementations risk getting wrong.
The developer plans more DSA revision projects. The pattern is sound: theory matters more when you've shipped code that doesn't scale.
Context: This is a learning exercise, not production software. But the performance gap it demonstrates - O(1) versus O(n) - explains why enterprise architects choose specific data structures. Working code becomes good code when it scales.