rotezecke
11-29-2012, 09:04 AM
hi
i have to sort a two dimensional array for google visualization api.
the unsorted data works fine.
structure of the unsorted array is:
[['stringA0',intB0],
['stringA1',intB1],
['stringA2'; intB2],
['stringA3'; intB3],
['stringA4'; intB4],
['stringA5'; intB5]]
i have to sort on the second element. as demonstrated above, first element is a string, second an integer, and this should remain so.
i use this function for sorting
myarray.sort(sortMultiDimensional);
function sortMultiDimensional(a,b)
{
// this sorts the array using the second element
return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
}but this turns the second element into a string. i didnt write the function (and i dont get it). where would i have to place parceInt() to make it work?
cheers
i have to sort a two dimensional array for google visualization api.
the unsorted data works fine.
structure of the unsorted array is:
[['stringA0',intB0],
['stringA1',intB1],
['stringA2'; intB2],
['stringA3'; intB3],
['stringA4'; intB4],
['stringA5'; intB5]]
i have to sort on the second element. as demonstrated above, first element is a string, second an integer, and this should remain so.
i use this function for sorting
myarray.sort(sortMultiDimensional);
function sortMultiDimensional(a,b)
{
// this sorts the array using the second element
return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
}but this turns the second element into a string. i didnt write the function (and i dont get it). where would i have to place parceInt() to make it work?
cheers