Ticker

6/recent/ticker-posts

Sorting ruby array based on one condition

Example

1.9.2p320 :013 > ["Carter's", "Gerber", "Petit Bateau (as pictured)"].sort_by { |word| word.include?('(as pictured)') ? 0 : 1}

 => ["Petit Bateau (as pictured)", "Gerber", "Carter's"] 


Post a Comment

0 Comments