Javascript program for the above approach
function maxindex ( dist , n ) { let mi = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( dist [ i ] > dist [ mi ] ) mi = i ; } return mi ; } function selectKcities ( n , weights , k ) { let dist = new Array ( n ) ; let centers = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { dist [ i ] = Number . MAX_VALUE ; }