Medium
This question is a daily question and will count towards your daily streak.
You're building a task queue that processes items in batches. What will be the final state of the processed array?
1class TaskQueue {2 constructor(batchSize = 2) {3 this.batchSize = batchSize;4 this.processed = [];5 }67 async processTasks(tasks) {8 for (let i = 0; i < tasks.length; i += this.batchSize) {9 const batch = tasks.slice(i, i + this.batchSize);10 const results = await Promise.all(11 batch.map(task => this.processTask(task))12 );13 this.processed.push(...results);14 }15 return this.processed;16 }1718 async processTask(task) {19 return `${task}-done`;20 }21}2223const queue = new TaskQueue(2);24const tasks = ['A', 'B', 'C'];2526queue.processTasks(tasks).then(console.log);