Skip to content

Instantly share code, notes, and snippets.

View jsimo237's full-sized avatar
🏠
Working from home

Joel Simo jsimo237

🏠
Working from home
View GitHub Profile
/**
* 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');
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
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")