| In: |
Springz.rb
basiclibrary.rb |
| Parent: | Object |
Extensions to the Array class
Processes each unique pair (of indices, not value) in the array by yielding them to the supplied block.
a = [1,2,3,4]
a.each_unique_pair{ |a,b|
puts a+','+b
}
=> 1,2
=> 1,3
=> 1,4
=> 2,3
=> 2,4
=> 3,4
Does not guarantee the uniqueness of values. For example:
a = [1,2,1]
a.each_unique_pair{ |a,b|
puts a+','+b
}
=> 1,2
=> 1,1
=> 2,1
Processes each unique pair (of indices, not value) in the array by yielding them to the supplied block.
a = [1,2,3,4]
a.each_unique_pair{ |a,b|
puts a+','+b
}
=> 1,2
=> 1,3
=> 1,4
=> 2,3
=> 2,4
=> 3,4
Does not guarantee the uniqueness of values. For example:
a = [1,2,1]
a.each_unique_pair{ |a,b|
puts a+','+b
}
=> 1,2
=> 1,1
=> 2,1