## digitalmars.D.learn - what does array.reverse really does?

• jicman (15/15) Mar 31 2006 I am trying to get rid of the first item of an array, so I am trying to ...
• Deewiant (7/30) Mar 31 2006 For one thing, it does it in-place, so you can just "a.reverse;" instead...
• jicman (4/34) Mar 31 2006 Yeah... This one would be much faster... :-) I had forgotten about thi...
• BCS (9/11) Mar 31 2006 watch out for this though
```I am trying to get rid of the first item of an array, so I am trying to figure
it out what is the best way.  Right I I thought of this,

char[][] a;
a = "a";
a = "b";
a = "c";
a = "d";

so if I want to get rid of the first one, I do

a = a.reverse
a.length = a.length - 1;
a = a.reverse;

But now I am thinking that what if the array is huge.  So, what does
array.reverse really does?

thanks,

josé
```
Mar 31 2006
```jicman wrote:
I am trying to get rid of the first item of an array, so I am trying to figure
it out what is the best way.  Right I I thought of this,

char[][] a;
a = "a";
a = "b";
a = "c";
a = "d";

so if I want to get rid of the first one, I do

a = a.reverse
a.length = a.length - 1;
a = a.reverse;

But now I am thinking that what if the array is huge.  So, what does
array.reverse really does?

thanks,

josé

For one thing, it does it in-place, so you can just "a.reverse;" instead of "a =
a.reverse;".

For another, to get rid of the first array element, I suggest "a = a[1..\$]",
which I would expect to be faster.

As to your question, I don't really know. Have a look at
```
Mar 31 2006
```Deewiant says...
jicman wrote:
I am trying to get rid of the first item of an array, so I am trying to figure
it out what is the best way.  Right I I thought of this,

char[][] a;
a = "a";
a = "b";
a = "c";
a = "d";

so if I want to get rid of the first one, I do

a = a.reverse
a.length = a.length - 1;
a = a.reverse;

But now I am thinking that what if the array is huge.  So, what does
array.reverse really does?

thanks,

josé

For one thing, it does it in-place, so you can just "a.reverse;" instead of "a =
a.reverse;".

For another, to get rid of the first array element, I suggest "a = a[1..\$]",
which I would expect to be faster.

Gosh, and I even used it a few months back... Read The Great Manual. :-)

Thanks.

As to your question, I don't really know. Have a look at

```
Mar 31 2006    BCS <BCS_member pathlink.com> writes:
```In article <e0jrkd\$2ou\$1 digitaldaemon.com>, Deewiant says...

For another, to get rid of the first array element, I suggest "a = a[1..\$]",
which I would expect to be faster.

watch out for this though

int[] a = [1, 2, ..stuff...]
int[] b = a;

b = b[1..\$];

assert(b == a);  //fails because only where b points to is changed.

somthing like this is needed to change the contents

foreach(int i, int j; a[1..\$])
b[i] = j;
```
Mar 31 2006