Array deletion

R

Robert Klemme

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. :)

robert
 
J

jazzez ravi

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
 
H

Heesob Park

2008/12/2 jazzez ravi said:
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 Heesob
 
P

Pit Capitain

2008/12/2 Heesob Park said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,186
Messages
2,570,997
Members
47,586
Latest member
Gilda57E93

Latest Threads

Top