How does closure work in JavaScript? Explain using the example of the variable index and the function run in your solution.
Frontend
Explain how Promise.all waits for all requests to complete in your recursive solution. Why might the current implementation return an incomplete result?
Tell me more about the project in Tsifrium: which modules were responsible, how was the feature organized — where were endpoints, models, business logic, subscriptions?
Have you used FSD (Feature-Sliced Design) in your project? How did you write samples and subscribe to events in Effector when using FSD?
How do you understand the choice of architecture? How do you distinguish the advantages and disadvantages between different approaches?
/** * Implement the function that will execute a callback with the data * and return an array of responses Response[]. * The solution should execute all requests in parallel * but no more than [limit] requests can be executed concurrently. * The goal is to minimize the total execution time. */ type Props<RequestData, Response> = { callback: (args: RequestData) => Promise<Response>; data: Array<RequestData>; limit: number; }; export async function runWithLimit<RequestData, Response>({ callback, data, limit, }: Props<RequestData, Response>): Promise<Response[]> { // START SOLUTION HERE if (limit < 1 || data.length === 0) { return Promise.resolve([]); } if (limit >= data.length) { return Promise.all(data.map(callback)); } const result: Response[] = new Array(data.length); let index = 0; const run = async () => { if (index >= data.length) return; const elem = data[index]; try { result[index] = await callback(elem); } catch (err) { result[index] = (err) as Response; // todo: handle error } index++; run(); }; const startPack = Array.from({ length: limit }, run); await Promise.all(startPack); return result; }
How does Array.from work? What arguments does it accept?
Build optimization: what did it consist of? What other approaches do you know for optimizing bundle size?
What is code splitting and how does it work?
Tell us about yourself and your work experience.