Class: Topchart

Inherits:
Object
  • Object
show all
Defined in:
lib/topchart.rb,
lib/topchart/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#chart(list1, list2) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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