class Topchart

Constants

VERSION

Public Instance Methods

chart(list1,list2) click to toggle source
# File lib/topchart.rb, line 5
def chart(list1,list2)
  chart = []

  rlist1 = list1.reverse
  rlist2 = list2.reverse

  s1 = Set.new(list1)
  s2 = Set.new(list2)

  new = s2 - s1

  chart += new.map do |el|
    [rlist2.index(el), el]
  end

  inter = s1.intersection(s2)
  chart += inter.map do |el|
    i1 = list1.index(el)
    i2 = list2.index(el)
    [i1-i2, el]
  end

  chart.sort.reverse
end