Javascript Examples

Page 2 of 3

javascriptSnippet

Curry a Function

Curry a function so partial application returns a new function until every argument is supplied, enabling reusable configured variants.

javascriptSnippet

Debounce a Function

Debounce wraps a callback so it runs only after activity stops for a set wait, collapsing bursts of calls into a single trailing invocation.

javascriptSnippet

Deep Clone Plain Data Objects

Clone nested objects and arrays without sharing references, using the structured clone algorithm so dates, maps, and cycles are handled correctly.

javascriptSnippet

Minimal Typed Event Emitter

Build a small publish and subscribe emitter that registers listeners per event name and supports one-shot subscribers and clean removal.

javascriptSnippet

Group Array Items by Key

Group an array of records into a map keyed by one of their fields, a building block for reports, indexes, and bucketed aggregations.

javascriptSnippet

Decode JWT Claims and Check Expiry

Decode the payload of a JSON Web Token and verify that its expiry and not-before claims are respected, without trusting the token's signature blindly.

javascriptSnippet

Levenshtein Edit Distance

Compute the minimum number of insertions, deletions, and substitutions between two strings, the basis of fuzzy matching and spell suggestions.

javascriptSnippet

LRU Cache With Map Ordering

Implement a least-recently-used cache that evicts the oldest entry when capacity is exceeded, reusing Map insertion order to track recency.

javascriptSnippet

Memoize With a Time to Live

Cache a function's result by argument key with an expiry, so expensive pure calls are reused briefly and stale values eventually recompute.

javascriptSnippet

Diff Two Flat Objects

Compare two flat objects field by field and report added, removed, and changed keys, the core of audit logging and change detection.

javascriptSnippet

Paginate an In-Memory Array

Slice an array into a page and return metadata such as total pages and whether more results follow, the shape most list endpoints expose.

javascriptSnippet

Bounded Concurrency Promise Pool

Run an array of async tasks with a maximum concurrency, so a large batch does not open all connections at once and overwhelm a downstream service.

javascriptSnippet

Throttle a Function

Throttle limits how often a function runs by allowing at most one call per interval, useful for scroll and resize handlers that fire continuously.

javascriptSnippet

Async Mutex With FIFO Waiters

Serialize critical sections with an async mutex that queues waiters in FIFO order, supports acquisition timeouts and safe double release.

javascriptSnippet

Cookie Header Parser

Parse a Cookie request header into a null-prototype object, handling quoted values, duplicates and RFC 6265 rules.