So for example, I have an array like that:
char[] pattern = "GCAGAGAG".ToCharArray();
And what I would like to do is to extract out distinct values and its corresponding indexes(smallest one) from right to left where first letters does not count.
example:
reversed array: GAGAGACG
Distinct values are: A, C, G
and the smallest index of each one is:
G = 2 (first G does not count)
A = 1
C = 6
So far I managed to do this but then I freeze, because I lack of knowledge connected with linq. I am still learning those things, so I am kind of "green" at them :)
var query = Pattern
.Reverse()
.Select((n, i) => new { Letter = n, Index = i })
.Where(n => n.Index > 0)
.OrderBy(n => n.Letter);
This gives the result, which is in attached picture.
Now I should group values by letter and find their min index value, but here I'll need your's help.
At the end I would like to cast result to dictionary but I am having trouble with it ... I tried with
.ToDictionary<char, int>(n => n.Letter, n => n.Index);
but that gives me an error. So how should I form this?