I've been banging my head against the wall all morning trying to figure this out. I'm working with the Google Distance Matrix API from which I'm getting an array of trip durations (in seconds) of which I need to apply the exact same ordering to another hard-coded array I've made of Beach Names. Then, after I get an array Beach Name - Durations elements, I need to sort through them in basic ascending order. But the sort will have to be done on what I think will have to be a nested object. Here's what I'm working with:
// Array of beach names
beachNamesArr = ["Kill Devil Hills Beach", "Wrightsville Beach", "Oak Island Beach", "Myrtle Beach", "Isle Of Palms Beach", "Hilton Head Island Beach", "Tybee Island Beach", "Saint Simons Island Beach", "Fernandina Beach", "Neptune Beach", "Saint Augustine Beach", "Daytona Beach", "Cape Canaveral Beach", "Palm Beach", "Fort Lauderdale Beach", "Miami Beach", "Naples Beach", "Clearwater Beach", "Alligator Point Beach", "Panama City Beach", "Pensacola Beach", "Gulf Shores Beach", "Dauphin Island Beach", "Biloxi Beach", "Bay Saint Louis Beach"]
// Array of trip durations from users current location in seconds
durationArr = [32943, 22969, 22879, 20306, 19709, 15659, 14489, 16924, 19328, 19551, 20918, 23180, 25435, 31079, 33490, 34425, 31316, 25289, 19107, 17924, 18420, 19589, 19231, 20520, 22181]
I need the elements positions in both arrays to stay the same because Kill Devil Hills is 32943 secs and Myrtle Beach is 20306 secs and so on .. Then i simply need to sort them ascending based on their duration.
I'm assuming that the new array will have to look something like:
combinedArr = ['Kill Devil Hills': {duration: 32943}, ... ]
but that honestly doesn't even look like an array so I don't know
Would much appreciate some help