System Design Quiz Practice
Active Recall Drill Session
← Exit SessionQuestion 1 of 1
mediumSystem Design
Given this RoundRobinBalancer over servers ["A","B","C"], what does calling .next() five times in a row produce?
code
class RoundRobinBalancer {
constructor(servers) { this.servers = servers; this.index = 0; }
next() {
const s = this.servers[this.index];
this.index = (this.index + 1) % this.servers.length;
return s;
}
}
const rr = new RoundRobinBalancer(["A","B","C"]);
for (let i = 0; i < 5; i++) console.log(rr.next());