Array deletion

Hi All,

have an array like,

a=[“one”,“xcxc”,“two”,“dadasd”,“three”,“hgfhgfh”]

I want to delete the index of a[1],a[3] and so on…

Thanks in advance,
P.Raveendran

On 02.12.2008 07:25, jazzez ravi wrote:

Hi All,

have an array like,

a=[“one”,“xcxc”,“two”,“dadasd”,“three”,“hgfhgfh”]

I want to delete the index of a[1],a[3] and so on…

Use delete_at - and read the documentation. :slight_smile:

robert

jazzez ravi wrote:

Hi All,

have an array like,

a=[“one”,“xcxc”,“two”,“dadasd”,“three”,“hgfhgfh”]

I want to delete the index of a[1],a[3] and so on…

Thanks in advance,
P.Raveendran
http://raveendran.wordpress.com

array.delete_at(index). use this to delete particular indexes in an
array.

Hi Vamsi and Robert,

delete_at(index) is useful when need to delete one data. But i want to
delete series like 1,3,5,7. Currently i am using loop for it. Any other
good code for it.

I tried Array.delete_at(1,3,7,9) → Like this

Thanks,
P.Raveendran
http://raveendran.wordpress.com

Hi Park,

Thanks for your code. I will catch u soon with another issue

Thanks all,

P.Raveendran
http://raveendran.wordpress.com

2008/12/2 jazzez ravi [email protected]:

Hi Vamsi and Robert,

delete_at(index) is useful when need to delete one data. But i want to
delete series like 1,3,5,7. Currently i am using loop for it. Any other
good code for it.

I tried Array.delete_at(1,3,7,9) → Like this

If there is no duplicate data, you can use values_at like this

a = a - a.values_at(1,3,5,7)

Regards,

Park H.

2008/12/2 Heesob P. [email protected]:

If there is no duplicate data, you can use values_at like this
(…)

Or apply Array#- to the indexes. This works with duplicate data, too:

a.values_at(*((0…a.size).to_a - [1, 3, 5, 7]))

Regards,
Pit