Search for a command to run...
Find the cheapest route between every pair of nodes
Initialize direct distances
Set the diagonal to zero, direct edges to their weights, and every unknown route to infinity.
Floyd-Warshall Algorithm
1function floydWarshall(distance) {2 for (let k = 0; k < distance.length; k++) {3 for (let i = 0; i < distance.length; i++) {//rows: 5columns: 5intermediate: none4 for (let j = 0; j < distance.length; j++) {5 distance[i][j] = Math.min(6 distance[i][j],7 distance[i][k] + distance[k][j]8 );9 }10 }11 }12}