I've come across a few similar posts regarding this issue, but none have provided solutions that work for my specific situation. I'm feeling lost on how to solve this problem (like Sort a 2D array by the second value)
Let me explain the challenge I'm facing in JavaScript;
I have two arrays that I'm using to generate a chart in a third-party tool. Here are the variables I'm working with;
label["Stock A", "Stock B", "Stock C", "Stock D"]
value["200", "1000", "900", "800"]
I would like to organize this data into a 2D array
sorted["Stock B, 1000","Stock C, 900", "Stock D, 800", "Stock A, 200"]
I want to sort based on the numerical value, if possible. The issue arises when I try the solution from the aforementioned question, as it only compares one value with another. I need it to go through all values stored in the array.
Last week, I stumbled upon a complicated method that sorted values like 100 and 1000 next to each other - which I initially thought was due to them not being integers, but that wasn't the case. In frustration, I deleted that code last Friday.
I'm hoping that someone out there can offer guidance to a novice coder like me. Since the values come in as strings, they'll need to be converted to integers.
The array could potentially have an unlimited number of entries, and once they're correctly sorted, I need to keep the top 10 and group the rest together with a total count - resulting in 11 entries. But sorting is the first hurdle I must overcome.
Thank you in advance for any assistance.