Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   array.reverse() (https://forums.graalonline.com/forums/showthread.php?t=86219)

cbk1994 06-07-2009 03:12 AM

array.reverse()
 
or array.flip()

It reverses (or flips) the order of an array. I don't think I need to illustrate this, but I will anyway.

a, d, s, h, r
array.reverse()
r, h, s, d, a

It would also be great to have

array.reverse(start index, end index)

a, d, s, h, r
array.reverse(1, 3)
a, h, s, d, r

DustyPorViva 06-07-2009 03:28 AM

Could always get Skyld to add something like:
PHP Code:

function flip(arr) {
  
temp.fliparr = new[arr.size()];
  for (
temp.i=0;i<arr.size();i++) {
    
fliparr[arr.size()-1-i] = arr[i];
  }
  return 
fliparr;


To the public functions... however, I agree.

Angel_Light 06-07-2009 03:45 AM

Not trying to be negative, seriously. But can anyone show me a use of this?

DustyPorViva 06-07-2009 04:12 AM

I'm sure there are a few moments in time someone would like to flip a list of whatever.

fowlplay4 06-07-2009 05:03 AM

Well it can be a shortcut for, for each loops.. like:

PHP Code:


temp
.array = {12345};

for (
temp.= (array.size()-1); 0); temp.i--) {
  echo(array[
i]);
}

for (
temp.val: array.reverse()) {
  echo(
val);


But other than that this usually doesn't pop up much.

Pelikano 06-07-2009 10:47 AM

You should be able to change the "keys" of arrays, just like in PHP.

Now, that would be something...

salesman 06-07-2009 06:28 PM

Quote:

Originally Posted by Angel_Light (Post 1497558)
Not trying to be negative, seriously. But can anyone show me a use of this?

My most recent encounter with something like this was looping through an array of nodes for a pathfinding script...this would've made things much easier.

Angel_Light 06-07-2009 07:02 PM

Alright, thanks you guys. I was literally drawing a blank of when I would ever use it, but the pathfinding thing made sense.

Chompy 06-07-2009 07:49 PM

I see no point for it to be added into the engine ;o

Gambet 06-07-2009 09:51 PM

Quote:

Originally Posted by Chompy (Post 1497674)
I see no point for it to be added into the engine ;o


Agreed.


With most languages you would have to do something like what Jer posted, and it's not like it's difficult to reverse arrays anyways. If Stefan is willing to update it to the engine then by all means go ahead, I just don't think it's one of those things that really needs to be there.


All times are GMT +2. The time now is 05:12 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.