ruby - Iterate over array whilst amending the same array -


The following array repetition works fine

  data = [17, 22, 12, 24] Data. Items | "Number: # {item}" end  

I would like to insert a new array in the same array instead of puts I fail to believe that it is making an infinite loop.

  Data = [17, 22, 12, 24] Data. Items | Data & lt; & Lt; I tried to do     

instead of But the same problem comes along.

If you want to add new items to the array, do so:

data = [17, 22, 12, 24] data.cunk data data.collect {| i | "number: # {i}"} # data => [17, 22 If you just want to change with the new items, 12, 24, "number: 17", "number: 22", "number: 12", "number: 24"]

Data content:

  data = date .collect {| i | "number: # {i}"}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -