Advertisement
Guest User

08 problem

a guest
Jul 21st, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Sorting an array means to arrange its elements in increasing order. Write a JavaScript function sortArray(value) to sort an array. Use the "selection sort" algorithm: find the smallest element, move it at the first position, find the smallest from the rest, move it at the second position, etc. Write JS program arraySorter.js that invokes your function with the sample input data below and prints the output at the console. Use a second array.
  2. function sortArray(argument) {
  3.     arr = argument;
  4.     arr.sort(function(a,b){return a - b});
  5.     console.log(arr.join(', '));
  6. }
  7. sortArray([5, 4, 3, 2, 1]);
  8. sortArray([12, 12, 50, 2, 6, 224, 51, 712, 6, 3, 3]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement