mercredi 2 décembre 2015

copy elements one by one from one array to another after it passes a condition in ruby

I am working on a ruby on rails project. In my controller I have an array and I need to copy all the from this array to another except the ones that does not pass the condition.

For example i have an array

a = [1,2,3,4,5]

i will take an input from the user. if the user's input is 3 then it has to copy all other elements from the array 'A' to array 'B' except 3. The array B has to be this [1,2,4,5]

How do i do this?

Aucun commentaire:

Enregistrer un commentaire