-1

I've seen things like this:
sorting arrays
and this
also sorting arrays

But I'm just not sure how to relate that to my code.
I have 4 arrays; three of which are numbers to be sorted in ascending and descending, but what is really stumping me is the fourth array which is all names and needs to be sorted alphabetically.
So how would I alter any of these past codes, or make a new one that would use the invokation of these 4 arrays

        var custName = new Array("Smith, Al","Toms, Andy","Jones, Zack","Vargas, Eddie","Donner, Alice","McMullen, Jessie","Nevins, Carol","Stark, Howard","Neeland, Franny","Boxby, Amos");

        var mnthCharge = new Array(140.00, 42.00, 18.00, 18.00, 36.00, 140.00, 42.00, 24.00, 140.00, 24.00);

        var pastDueAmt = new Array(0, 0, 84.00, 36.00, 0, 18.00, 42.00, 42.00, 96.00, 0);

        var dayPastDue = new Array(0, 0, 60, 60, 0, 30, 90, 30, 120, 0);

Or at least the first one to be alphabetical.

Community
  • 1
  • 1
  • You said you're stumped on the "fourth array." What code did you use that worked for the other three? – Shawn Bush Feb 05 '15 at 18:46
  • Essentially I just meant that I can figure out the other three if need be, but I said that the alphabetical one "really stumped" me. Simply because from the links I posted they are using string invocations and I am using and array, so i'm not entirely sure how to make the changes to the code. Even any helpful links would be appreciated. – PinkMonkeyBird Feb 05 '15 at 18:51
  • for(String s : custName){ for(int i=0; i< s.length; ++i){ string.charat(i) Apply sorting algorithm here } } – TheBetaProgrammer Feb 05 '15 at 19:00

1 Answers1

0

Are you writing Scala code here? If so, I think the right way to sort an array should be:

var custName = Array("Smith, Al","Toms, Andy","Jones, Zack","Vargas, Eddie","Donner, Alice","McMullen, Jessie","Nevins, Carol","Stark, Howard","Neeland, Franny","Boxby, Amos")
custName = custName.sortWith(_ < _)

The Array.sortWith() function implemented quick sort algorithm.

Chong Tang
  • 2,066
  • 15
  • 12