00:00
00:00
Newgrounds Background Image Theme

Kiler91 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Reorder Array with Array?

1,013 Views | 1 Reply
New Topic Respond to this Topic

Reorder Array with Array? 2019-10-25 05:31:22


I'm collecting a list of folders.


They're outputted as for example

["country-denmark", "country-finland", "country-norway", "country-sweden", "country-zzzzz"];


If I'd like to reorder three of them, I'd like a way I can create another array


["country-sweden", "country-finland", "country-norway"];


And it would make the original array ["country-denmark","country-sweden", "country-finland", "country-norway", "country-zzzzz"]


So it would only move the ones mentioned, into the order the new array suggested, at the exact place when the first one was mentioned.


Ideally, if there was more sorting arrays, those ones would also get used. But if they didn't exist, it wouldn't throw an error.


My plan would be to go through a for loop, pop all the ones mentioned in the new array, insert the array into whereever the first one was mentioned. But I'm thinking there's probably a simpler way?

Response to Reorder Array with Array? 2019-10-26 23:42:47


At 10/25/19 05:31 AM, Aprime wrote: I'm collecting a list of folders.

They're outputted as for example
["country-denmark", "country-finland", "country-norway", "country-sweden", "country-zzzzz"];

If I'd like to reorder three of them, I'd like a way I can create another array

["country-sweden", "country-finland", "country-norway"];

And it would make the original array ["country-denmark","country-sweden", "country-finland", "country-norway", "country-zzzzz"]

So it would only move the ones mentioned, into the order the new array suggested, at the exact place when the first one was mentioned.

Ideally, if there was more sorting arrays, those ones would also get used. But if they didn't exist, it wouldn't throw an error.

My plan would be to go through a for loop, pop all the ones mentioned in the new array, insert the array into whereever the first one was mentioned. But I'm thinking there's probably a simpler way?


If you were using python you could use list slicing use the sorted function on the result to order it.


Tempus Edax Rerum

BBS Signature