Prevent initial array from sorting

Posted by George on Stack Overflow See other posts from Stack Overflow or by George
Published on 2010-04-26T15:16:58Z Indexed on 2010/04/26 15:23 UTC
Read the original article Hit count: 157

Filed under:
|
|

I have an array where the order of the objects is important for when I finally output the array in a document. However, I'm also sorting the array in a function to find the highest value. The problem is that I after I run the function to find the highest value, I can't get the original sort order of the array back.

// html document
var data = [75,300,150,500,200];

createGraph(data);

// js document

function createGraph(data) {

    var maxRange = getDataRange(data);

    // simpleEncode() = google encoding function for graph
    var dataSet = simpleEncode(data,maxRange);

}

function getDataRange(dataArray) {
    var num = dataArray.sort(sortNumber);
    return num[0];
}

I've also tried setting data to dataA and dataB and using dataB in the getDataRange function and dataA in the simpleEncode function. Either way, data always end up being sorted from highest to lowest.

© Stack Overflow or respective owner

Related posts about arrays

Related posts about sorting