Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
sort an array by another array?
EvanReese
Member, Mentor Posts: 2,135 ✭✭✭✭✭
I have an array of faces that are in a seemingly random order in the array (by index), but they are arranged linearly enough that I could measure them from a certain point and get a sortable list of values. How do I use the array of distances to re-order the array of faces?
Maybe this question is too specific and there's actually a better approach altogether. If so I'd love to hear it.
Maybe this question is too specific and there's actually a better approach altogether. If so I'd love to hear it.
Evan Reese
0
Best Answers
-
MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭@Evan_Reese
Did you know that the FeatureScriptmap
s allow the key to be anything? [1]
Because of this, you can have a map of distances, indexed by the face Query. This makes sorting very simple, just using Onshape's sort function:<pre>sort(arrayOfQueries, function(a, b) { return distances[a] - distances[b] }) </pre>
[1]: Values and Types0 -
MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭@Evan_Reese
Here is an example:// This map gets filled out with the keys being `Query`s and the values being `ValueWithUnits`s. var queryToDistance is map = {}; var queryArray is array = ...; for query in queryArray { queryToDistance[query] = evDistance(context, ...); } queryArray = sort(queryArray, function(a, b) { return queryToDistance[a] - queryToDistance[b] });
0
Answers
Did you know that the FeatureScript
map
s allow the key to be anything? [1]Because of this, you can have a map of distances, indexed by the face Query. This makes sorting very simple, just using Onshape's sort function:
<pre>sort(arrayOfQueries, function(a, b) { return distances[a] - distances[b] }) </pre>
[1]: Values and Types
IR for AS/NZS 1100
Here is an example:
IR for AS/NZS 1100