Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def position(arr, item)
- arr.each_index {|i| return i if arr[i] =~ /#{item}/}
- end
- a_a = "widget_1;widget_3;widget_2;|widget_5|".split("|")
- a_b = "widget_1;widget_3;widget_2;||widget_5".split("|")
- puts position(a_a, "widget_5")
- puts position(a_b, "widget_5")
- puts position(a_a, "widget_1")
- puts position(a_b, "widget_1")
Add Comment
Please, Sign In to add comment