How can I possibly sort this in JavaScript?
        Posted  
        
            by orokusaki
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by orokusaki
        
        
        
        Published on 2010-05-06T04:54:27Z
        Indexed on 
            2010/05/06
            4:58 UTC
        
        
        Read the original article
        Hit count: 285
        
I've been pounding my head on the wall trying to figure out how to sort this in JavaScript (I have to work with it in this format unfortunately).
I need to sort it based on Small, Medium, Large, XL, XXL (Small ranking the highest) in each variationValues size field. The problem is that I need to sort the variationCosts and variationInventories at the same time to match the new order (since each value in order corresponds to the values in the other fields :(
Input I have to work with
var m = {
    variationNames: ["Length", "Size"  ],
    variationValues: [
        ["26.5\"", "XXL"], 
        ["25\"", "Large"], 
        ["25\"", "Medium"], 
        ["25\"", "Small"], 
        ["25\"", "XL"], 
        ["25\"", "XXL"], 
        ["26.5\"", "Large"], 
        ["26.5\"", "Small"], 
        ["26.5\"", "XL"]
    ],
    variationCosts: [
        20.00, 
        20.00, 
        20.00, 
        20.00, 
        20.00, 
        20.00, 
        20.00, 
        20.00, 
        20.00
    ],
    variationInventories: [
        10, 
        60, 
        51, 
        10, 
        15, 
        10, 
        60, 
        10, 
        15
    ],
    parentCost: 20.00
};
Desired output
var m = {
    variationNames: ["Length", "Size"  ],
    variationValues: [
        ["25\"", "Small"],
        ["26.5\"", "Small"],
        ["25\"", "Medium"],
        ["25\"", "Large"],
        ["26.5\"", "Large"],
        ["25\"", "XL"],
        ["26.5\"", "XL"]
        ["25\"", "XXL"],
        ["26.5\"", "XXL"],
    ],
    variationCosts: [
        20.00,
        20.00,
        20.00,
        20.00,
        20.00,
        20.00,
        20.00,
        20.00,
        20.00
    ],
    variationInventories: [
        10,
        10,
        51,
        60,
        15,
        15, 
        15,
        10,
        10
    ],
    parentCost: 20.00
};
© Stack Overflow or respective owner