Bird
0
0

Identify the bug in this notification function and select the fix:

medium📝 Analysis Q14 of 15
LLD - Design — Food Delivery System

Identify the bug in this notification function and select the fix:

function notifyAll(parties, message) {
  for (let i = 0; i < parties.length; i++) {
    parties.send(message)
  }
}
ARemove the loop and call <code>parties.send(message)</code> once
BAdd a return statement inside the loop
CChange <code>i < parties.length</code> to <code>i <= parties.length</code>
DChange <code>parties.send(message)</code> to <code>parties[i].send(message)</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify incorrect method call

    The code calls send on the entire parties array instead of individual party objects.
  2. Step 2: Fix by indexing the array

    Use parties[i].send(message) to call send on each party in the loop.
  3. Final Answer:

    Change parties.send(message) to parties[i].send(message) -> Option D
  4. Quick Check:

    Call send on each party object [OK]
Quick Trick: Call send on parties[i], not parties array [OK]
Common Mistakes:
  • Calling send on the whole array
  • Using wrong loop condition
  • Adding unnecessary return inside loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes