Guest User

Untitled

a guest
May 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. def position(arr, item)
  2. arr.each_index {|i| return i if arr[i] =~ /#{item}/}
  3. end
  4.  
  5. a_a = "widget_1;widget_3;widget_2;|widget_5|".split("|")
  6. a_b = "widget_1;widget_3;widget_2;||widget_5".split("|")
  7.  
  8. puts position(a_a, "widget_5")
  9. puts position(a_b, "widget_5")
  10.  
  11. puts position(a_a, "widget_1")
  12. puts position(a_b, "widget_1")
Add Comment
Please, Sign In to add comment