** ruby : array의 요소들을 random하게 섞는 방법

ar = (1..10).to_a

ar = ar.sort_by { rand }

 

puts ar.inspect  #확인

 

 

** array의 index, value를 동시에 접근하면서 loop 도는 방법

ar = (1..10).to_a

ar.each_with_index {|x, y| puts x, y}

 

 

+ Recent posts