vendredi 8 mai 2015

ruby - split an array into sub arrays when a value changes and ignore/delete that value

I want to split the following array into sub arrays so that the sub-arrays start and finish when the 1's start and finish...

a=[1,1,0,0,1,0,1,1,1]

so I end up with this as a new array...

=> [[1,1],[1],[1,1,1]]

anyone got any ideas...?

thanks in advance Matt

Aucun commentaire:

Enregistrer un commentaire