frontend-challenges
frontend-challenges copied to clipboard
FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
index.ts ```ts index.ts export const shuffle = (arr: number[]) => { let result: number[] = []; for (let i = 0; i < arr.length; i++) { const randIndex = Math.floor(Math.random()...
index.js ```js index.js export function debounce(func, delay, options = {}) { const { leading = false, trailing = true } = options; let timerId; const debounced = function () {...
index.js ```js index.js export function throttle(func, wait, options = {}) { const { leading = true, trailing = true } = options; let timer = null; let lastArgs = null;...
index.js ```js index.js export function throttle(cb, delay = 250) { let shouldInvoke = true; return (...args) => { if (shouldInvoke) { shouldInvoke = false; cb.call(this, ...args); setTimeout(() => { shouldInvoke...
index.js ```js index.js function curry(fn) { function curried(...args) { // If enough args and no placeholders → call fn if (args.length >= fn.length && args.every(arg => arg !== __)) {...
index.js ```js index.js /** * @param {Function} fn - original function to curry * @returns {Function} */ export function curry(fn) { return function curried(...args) { if (args.length >= fn.length) {...
index.ts ```ts index.ts /** * Retrieves a value from an object via a path. */ export function get( object: T, path: string | Array, defaultValue?: R, ): R | unknown...
index.ts ```ts index.ts export function deepClone(value: T): T { if (typeof value !== "object" || value === null) { return value; } if (Array.isArray(value)) { return value.map((item) => deepClone(item)) as...
index.ts ```ts index.ts /** * Converts a snake_case string to camelCase. */ export function snakeToCamel(input: string): string { const words = input.split("_").filter(Boolean); for (let i = 0; i < words.length;...
index.ts ```ts index.ts export async function retryPromise(fn: () => Promise, retries: number): Promise { return fn().catch((error) => { if (retries > 0) { return retryPromise(fn, retries - 1); } throw...