Within my code, there exists an array known as generationArray
. Each array contained within generationArray consists of 252 elements. The first 250 elements serve as internal coding data, while the final two positions are designated for sorting criteria. The second-to-last position holds a boolean
value, and the last position holds a number.
My objective is to arrange the generationArray
first by the boolean values (true or false) in each array, followed by the numeric value. If the last position holds true, prioritize higher numbers first; if it's false, prioritize lower numbers first.
For example, if generationArray
contains 5 arrays:
generationArray[0][last] == false
generationArray[0][last-1] == 350
generationArray[1][last] == true
generationArray[1][last-1] == 300
generationArray[2][last] == true
generationArray[2][last-1] == 250
generationArray[3][last] == false
generationArray[3][last-1] == 380
generationArray[4][last] == true
generationArray[4][last-1] == 290
The desired order would be:
generationArray[0][last] == true
generationArray[0][last-1] == 300
generationArray[1][last] == true
generationArray[1][last-1] == 290
generationArray[2][last] == true
generationArray[2][last-1] == 250
generationArray[3][last] == false
generationArray[3][last-1] == 350
generationArray[4][last] == false
generationArray[4][last-1] == 380
How can I accomplish this sorting in Javascript?