I've seen another couple of posts similar to this question, but none work for my scenario and at a lost how to solve this (such as Sort a 2D array by the second value)
I will explain the problem - which I am facing within JavaScript;
I have two arrays, which I am using to create a chart within a 3rd party product. I have the following variables;
label["Stock A", "Stock B", "Stock C", "Stock D"]
value["200", "1000", "900", "800"]
I would like this in a 2D array
sorted["Stock B, 1000","Stock C, 900", "Stock D, 800", "Stock A, 200"]
I want to sort by the numerical value, if possible. The problem is that when I use the solution within the question posted above, it only compares the value with one other value. I need this to go through each value already stored within the array.
I found another really long winded way somewhere last week, but it was sorting values such as 100, 1000 next to each other - which I thought was down to not being integers etc but no such luck. I deleted the code in a rage on Friday.
I was hoping that some kind soul at there could help a new coder. O the values come in as strings so they will need to be converted to ints.
There is an unlimited amount of entries in the array, and once I've sorted these correctly I need to keep the top 10 and then group the others into a group with a total - so I would have 11 entries. However I need to sort before I can tackle that.
Thanks in advance.