//JavaScript program for the //Selection Sort algorithm. //TRY //list = new Array("Valente", "Mason", "Gibbs", "Hargrove", "Ford"); list = new Array( 40, 30, 20, 50, 15); N = list.length; //A LOOP FOR EACH OF THE N-1 PASSES //USE start = 0, THEN start = 1, ..., FINALLY start = N-1 start = 0; while (start < N-1) { //FOR EACH PASS THROUGH list //FIND SMALLEST AMONGST list[start] ... list[N-1] loc = start; //location of leftmost item i = start + 1; //location of first item to be compared while (i < N) { if (list[i] < list[loc]) loc = i; //update location of "smallest" i++; } temp = list[loc]; //SWAP SMALLEST WITH ITEM AT LEFT END list[loc] = list[start]; list[start] = temp; start++; //UPDATE start FOR NEXT PASS } list //SHOW LIST AT BOTTOM