PDA

View Full Version : "Reversing" Arrays


projectigi
02-15-2007, 06:14 PM
Hrm, is there a function that reverses a array?
like
this.array[ 0 ] = 2;
this.array[ 1 ] = 3;
this.array[ 2 ] = 1;

now this.array.reverse(); or something like this would make

this.array[ 0 ] == 1;
this.array[ 1 ] == 3;
this.array[ 2 ] == 2;

Chompy
02-15-2007, 07:44 PM
Make a function for it..?

Chandler
02-15-2007, 07:52 PM
Can I ask why you would want to do this?


temp.myArray = {3, 5, "test"};
for (temp.curPar = (temp.myArray.size() - 1); temp.curPar > -1; temp.curPar--)
{
temp.newArray.add(temp.myArray[temp.curPar]);
}
echo(temp.newArray);

projectigi
02-15-2007, 08:01 PM
making a function is easy

but before i make a function i ask if theres already another function that does the same thing

Gambet
02-15-2007, 08:02 PM
making a function is easy

but before i make a function i ask if theres already another function that does the same thing


You should check the wiki more often.

Chandler
02-15-2007, 08:10 PM
making a function is easy

but before i make a function i ask if theres already another function that does the same thing

There isn't an option :(

Admins
02-15-2007, 09:27 PM
There is not (yet). We could add a few more string and array operators if wanted though.

projectigi
02-16-2007, 12:15 AM
Well, the wiki's search function sucks

xXziroXx
02-16-2007, 01:57 AM
Well, the wiki's search function sucks

Go to for example the clientside scripting page, CTRL + F and type in what you are looking for. Voilá, check mate.

Inverness
02-16-2007, 02:06 AM
Some string functions I use sometimes.

ReverseArray:
public function reversearray(temp.array) {
temp.newarray;
temp.i;

newarray = "";
for (i = array.size() - 1; i > -1; i --) {
newarray.add(array[i]);
}
return newarray;
}
ReverseString:
public function reversestring(temp.string) {
temp.i;
temp.out;

for (i = string.length() - 1; i > -1; i --) {
out @= string.charat(i);
}
return out;
}
ReplaceSubString:
public function replacesubstring(temp.string, temp.position, temp.length, temp.newstring) {
temp.stringa;
temp.stringb;
temp.outstring;

if (position < 0) {
return;
}
stringa = string.substring(0, position);
stringb = string.substring(position + length, -1);
outstring = stringa @ newstring @ stringb;
return outstring;
}