Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by headkit · May 03, 2010 at 09:16 AM · arraymerge

merging multidimensional arrays

hi folks!

i have a multidimensional array and i want to merge all its content to one big onedimensional array with randomized order.

is there an easy way in unity do do this?

thnx!

EDIT:

i want to merge

arr1 = ["foo 1", "bar 1"]; arr2 = ["foo 2", "bar 2"];

arr12 = [arr1, arr2] = [ ["foo 1", "bar 1"], ["foo 2", "bar 2"] ];

//searching for a method to quickly have

arrMerged = ["foo 1", "bar 1", "foo 2", "bar 2"];

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ben 2 · May 03, 2010 at 11:24 AM 0
Share

You might want to add more detail to this like what language you're using. In Unity you could do this in Javascript or C#.

avatar image headkit · May 03, 2010 at 11:30 AM 0
Share

for now i use javascript. but both ways should be interesting to different people...

avatar image duck ♦♦ · May 03, 2010 at 05:12 PM 0
Share

Are you looking to merge "true" multidimensional arrays, or are you using nested javascript arrays?

avatar image headkit · May 04, 2010 at 07:48 AM 0
Share

uh, aeh, whats the difference?

avatar image Cyclops · May 05, 2010 at 08:37 PM 0
Share

@headkit, remember to upvote good answers (in addition to checkmarking).

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Max Kaufmann · May 04, 2010 at 02:54 PM

One options is to do a randomized Insertion-Sort (http://en.wikipedia.org/wiki/Insertion_sort). Of course, there's hackier ways, too:

// merge contents, adding a random prefix
var letters = [ "a", "b", "c", ... ];
var result = [];
for (var i=0; i<arrays.Length; i++) {
   for (var j=0; j<arrays[i].Length; i++) {
     result = result.Push( letters[Random.Range(0,26)] + arrays[i][j] );
   }
}
// sort on the random prefixes to shuffle
result.Sort(); 
// removing the random prefixes
for (var i=0; i<result.Length; i++) {
  result[i] = result[i].Substring(1,result[i].Length);
}
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image headkit · May 05, 2010 at 07:34 AM 0
Share

interesting way!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Array index is out of range 1 Answer

Trying to get Vector3 Array to sort in order of Y values - C sharp 1 Answer

3D array flattening / unflattening to / from compute shader 1 Answer

Multiple spawn points using Array... 1 Answer

how subtract total value element of array ?? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges