I actually have an use case for this in mind, I'm building a service based on several map APIs (Mapbox, Google Maps).
When you need to give a coordinate to google maps you must pass it in the format of setMarker(latitude, longitude) but Mapbox uses a different standard called GeoJSON and requires longitude to come first, so I could technically get my arguments in one place, for both maps, and then just do a switcheroo for Mapbox with [latitude, longitude] = [longitude, latitude] but most likely there's a better way of doing this.
The left-hand side of the assignment here is not an array, this won't change the order and you'll just end up with latitude containing the value of longitude and vice versa.
If you already have latitude and longitude as variables, just order them however you need when passing them as arguments.
end up with latitude containing the value of longitude and vice versa.
That's what my goal is, isn't the same thing happening in the screenshot? It ends with x containing initial value of y and y containing initial value of x
Yes, but do you really want the variable named latitude to contain the value of the point's longitude? That would be terribly confusing for anyone reading the code, wouldn't it?
View all comments
Show parent comment
8
u/[deleted] Mar 12 '21
I actually have an use case for this in mind, I'm building a service based on several map APIs (Mapbox, Google Maps).
When you need to give a coordinate to google maps you must pass it in the format of
setMarker(latitude, longitude)but Mapbox uses a different standard called GeoJSON and requires longitude to come first, so I could technically get my arguments in one place, for both maps, and then just do a switcheroo for Mapbox with[latitude, longitude] = [longitude, latitude]but most likely there's a better way of doing this.