JavaScript
JavaScript copied to clipboard
added changes to your bellmanford.js
The change replaces the final loop with a direct return statement. Previously, the code looped through all vertices to find the destination and then returned its distance. This loop was unnecessary because the destination index is already known. By using:
return dis[dest]
the code becomes more efficient and readable. It removes redundant iterations, reduces time complexity for that part from O(V) to O(1), and makes the function cleaner without affecting the output.