Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mac="0800273B51A9"
- # With reject
- mac.split(/(..)/).reject {|c| c.empty?}.join(':')
- # With Inject
- mac.split(//).inject([]) do |nmac, e|
- if x.nil? or x>0
- nmac[nmac.size-1] = nmac[nmac.size-1] + e
- x=0
- else
- nmac[nmac.size] = e
- x=x+1
- end
- nmac
- end.join(':')
- mac.split(//).inject([]) { |m, e| if x.nil? or x>0 ;
- m[m.size-1] = m[m.size-1] + e ; x=0 ; else ; m[m.size] = e ;
- x=x+1 ; end ; m }.join(':')
Add Comment
Please, Sign In to add comment