Scenario 1
a = ['R1,R2','R3,R4','R5,R6', 'R2,R1', 'R4,R3']
Result:
a.uniq {|x| x.split(",").sort.join(',')}
Output => ["R1,R2", "R3,R4", "R5,R6"]
Scenario 2
a = ['R1,R2','R3,R4','R5,R6', 'R2,R1', 'R4,R3']
Result:
require 'set'
a.uniq {|x| Set.new(x.split(','))}
Output => ["R1,R2", "R3,R4", "R5,R6"]
a = ['R1,R2','R3,R4','R5,R6', 'R2,R1', 'R4,R3']
Result:
a.uniq {|x| x.split(",").sort.join(',')}
Output => ["R1,R2", "R3,R4", "R5,R6"]
Scenario 2
a = ['R1,R2','R3,R4','R5,R6', 'R2,R1', 'R4,R3']
Result:
require 'set'
a.uniq {|x| Set.new(x.split(','))}
Output => ["R1,R2", "R3,R4", "R5,R6"]
No comments:
Post a Comment