This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Fetches a random cat fact from a public API | |
| * Returns a clean JSON with selected fields | |
| */ | |
| async function fetchCatFact() { | |
| try { | |
| // 1. Make API call | |
| const response = await fetch('https://catfact.ninja/fact'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function processEvents(events, window = 10) { | |
| // Track the last allowed timestamp per user | |
| const lastAllowed = new Map(); | |
| const results = []; | |
| for (const [timestamp, userId] of events) { | |
| const lastTime = lastAllowed.get(userId); | |
| // Allowed if no previous allowed event for this user, | |
| // or if the difference meets the window requirement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findUniqueSumPairs(numbers, target) { | |
| // Validate input: must be an array with at least 2 numbers | |
| if (!Array.isArray(numbers) || numbers.length < 2) { | |
| return []; | |
| } | |
| // 'seen' keeps track of numbers we have already processed (O(1) lookup) | |
| const seen = new Set(); | |
| // 'pairsMap' stores unique pairs using a normalized string key (e.g. "2-5") |