I have this Javascript below, and I know that there is probably a better way of doing what I have done, so if you would like to share a better way, please do and I will definitely use it.
var Apeople = ["bob", "joe", "jane", "mike", "henry", "alex"];
var Abdays = ["08/20", "01/23", "04/19", "08/16", "01/08", "04/02"];
Apeople and Abdays line up with each other, so Janes birthday is 04/19.
I know I’m not supposed to use eval() so if you know of a better way please tell me.
var mnths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
for(i=0; i<mnths.length; i++){
eval("var "+mnths[i]+" = []");
}
for(i=0; i<Abdays.length; i++){
var ab = Abdays[i];
if(ab.substring(0,1) == "0"){
var mn = ab.substring(1,2); //month number without 0 before it
} else {
var mn = ab.substring(0,2); //month number if 11 or 12
}
eval(""+mnths[mn-1]+".push(i)");
}
Now I have January=[1,4] April=[2,5] August=[0,3]. I did this so I can find out whos name goes with what birthday.
For example Apeople[January[0]] would be joe and Abdays[January[0]] would be 01/23.
What I need to do is put each months entries in order by which comes first going by the birthdays. Abdays[January[0]] is 01/23 but Abdays[January[1]] is 01/08 so they should be swapped.
As I am typing this I am thinking that I probably should have used JSON.
So what I need help with is putting the birthdays in order while still being able to tell which birthday goes to which name, and at the same time possibly finding a better way to write this code.
You can sort the
Abdaysarray like this.I randomly selected 2010. You will have to modify this, add more conditions if you need and write code to sort
Apeopleaccording to sortedAbdays.UPDATE:
Quickly written. You can find better ways, but hope this helps