I'd want to know how many times a value is mentioned in a list. For instance list with following values:
blue
blue
green
yellow
needs to output
blue - 2
green - 1
yellow - 1
This is what Ive come up with, but it wont work :S
blue
blue
green
yellow
needs to output
blue - 2
green - 1
yellow - 1
This is what Ive come up with, but it wont work :S
B4X:
Sub get_percentages(l As List) As List
Dim templist As List
Dim S As String
Dim output As List
l.Sort(True)
output.Initialize
templist.Initialize
templist = l
For i=0 To 3
S = l.Get(i)
For i=0 To templist.Size -1
If S = templist.Get(i) Then
Dim P As percentage
P.name = S
P.number = P.number +1
templist.Set(i, "counted")
End If
Next
If P.number > 0 Then output.Add(P)
Next
For i=0 To output.Size-1
Dim P As percentage
P= output.Get(i)
P.percentage = P.number/l.Size
output.Set(i, P)
Next
Return output
End Sub