PDA

View Full Version : Reverse array



nickdigital
02-08-2013, 01:51 PM
Can you reverse an array in lscript?

I couldn't find any syntax reference.

jeric_synergy
02-08-2013, 02:20 PM
"Reverse" in what sense?

nickdigital
02-08-2013, 02:42 PM
"Reverse" in what sense?

myarray[1] = "hi";
myarray[2] = "bye";

myarray.reverse(); <--- if this was a valid command would result in:

myarray[1] = "bye";
myarray[2] = "hi";

dpont
02-08-2013, 02:53 PM
myarray[1] = "hi";
myarray[2] = "bye";

myarray.reverse(); <--- if this was a valid command would result in:

myarray[1] = "bye";
myarray[2] = "hi";

Don't know this reverse command, but you could try something like:
myarray[myarray.size() - index]

Denis.

nickdigital
02-08-2013, 02:55 PM
Don't know this reverse command, but you could try something like:
myarray[myarray.size() - index]

Denis.

Hi Denis,

I made up .reverse. It's valid in javascript. I'm hoping lscript has an equivalent.

jeric_synergy
02-08-2013, 03:11 PM
I think you're going to have to write that one yourself. :(

xchrisx
02-08-2013, 04:58 PM
I don't think I've seen anything like a reverse array for lscript. Personally, I would do as Denis suggests and just iterate through them in reverse.

Sensei
02-08-2013, 07:33 PM
entry is type of element used by table.

entry table[]
int size; // size of table
int half_size = size / 2;
for( int i = 0; i < half_size; i++ )
{
entry temp = table[ i ];
table[ i ] = table[ size - 1 - i ];
table[ size - 1 - i ] = temp;
}

You can change it to any language.