System Design Quiz Practice
Active Recall Drill Session
← Exit SessionQuestion 1 of 1
mediumSystem Design
Given this ShardRouter with numShards=3, what's true about repeated calls to shardFor with the SAME key?
code
function simpleHash(key) {
let h = 0;
for (let i = 0; i < key.length; i++) h = (h * 31 + key.charCodeAt(i)) >>> 0;
return h;
}
class ShardRouter {
constructor(n) { this.numShards = n; }
shardFor(key) { return simpleHash(key) % this.numShards; }
}
const r = new ShardRouter(3);
console.log(r.shardFor("user_123") === r.shardFor("user_123"));