What I want to do is sort the elements of these arrays:
name[];
standing[];
value[];
maxvalue[];
id[];
repstring[];
By a sorting array:
var SortArr = [1,2,4,6,3,5,7,8,12,11,10,9...etc]
all the way up to 106 which is the length of these arrays.
This sorting array is meant to be a key to rearrange the data in a custom way, not alphabetically.
What is a way to do this efficiently? I've looked at trying to combine the above arrays into an object as I've been reading this might be the best way to do this(?) but I can't figure out how. I'm very new to javascript and coding in general so any pointers are welcome. Thanks
This is my code below:
}
//...
//this is all within a function called rep()
//Declare things
var name = [ ];
var standing = [ ];
var value = [ ];
var maxvalue = [ ];
var id = [ ];
//For converting repstanding to strings
var reputation = new Array ("Hated", "Hostile", "Unfriendly", "Neutral", "Friendly", "Honored", "Revered", "Exalted");
//array holding converted strings for each faction
var repstring = [ ];
var count = toon.reputation.length; //this value is 106
//Populate arrays
for (i = 0; i < count; i++)
{
name[i] = toon.reputation[i].name; //string
standing[i] = toon.reputation[i].standing; //number from 0-7
value[i] = toon.reputation[i].value; // number from 0-21000
maxvalue[i] = toon.reputation[i].max; //number from 3000-21000
id[i] = toon.reputation[i].id //number from 1-1741
}
//Convert standing numbers to reputation string
for (i=0; i < count; i++)
{
repstring[i] = reputation[standing[i]];
}
//Create output array
var repInfo = new Array(
name, standing, repstring, value, maxvalue, id, SortArr
)
//Output array
return repInfo;
}
EDIT: This is example output from my function: (note: this only shows values 1-5 for each array, there are 106 values in each array)
Name Standing Repstring Value MaxValue ID SortArr
The Black Prince 3 Neutral 2800 3000 1359 5
The Sons of Hodir 0 Hated 0 36000 1119 3
Booty Bay 3 Neutral 1875 3000 21 2
Zandalar Tribe 3 Neutral 0 3000 270 1
The Oracles 3 Neutral 0 3000 1105 4
Ok so what I want to do is rearrange these so that they are ordered by SortArr, so it would look like this:
Name Standing Repstring Value MaxValue ID SortArr
Zandalar Tribe 3 Neutral 0 3000 270 1
Booty Bay 3 Neutral 1875 3000 21 2
The Sons of Hodir 0 Hated 0 36000 1119 3
The Oracles 3 Neutral 0 3000 1105 4
The Black Prince 3 Neutral 2800 3000 1359 5