I got two arrays A and B, A contains the KM and B contains value
A = [9,18,27,36,45,54,63,72,81,90,99,108,117,126]
B = [1,1,2,1,1,3,4,5,2,1,1,3,6,1]
I have to remove the repeated values and store the unique value from
here,
This is the desire
Output: A = [9,27,54,63,72,117,126]
B = [1,2,3,4,5,6,1]
But there is unique case in output in the last value of Array B, the
same value(1) already exits but it is still stored again.
The pattern which I tried to make is store the first value of array A
and B as base and start comparing
C = [9]
D = [1]
For first case I wrote if a[0]%c.reverse[0]==0 then check the value if
b|0| ==d|0| if both cases true ignore the value else store the new value
in C and D.
This pattern works but How to write code for it, this is what I tried:
(a.length)times do |aa|
(c.length).times do |cc|
if a[aa]%c[cc]==0 && b[aa]==d[cc]
puts “the value is already there”
else
c.push(aa) // I know if I do this it will start repeating
end
end
end