local undupeitems = {}
for _, v in ipairs(items) do
local undupe = true
if #undupeitems == 0 then
table.insert(undupeitems, v)
else
for _, v2 in ipairs(undupeitems) do
if v == v2 then
undupe = false
end
end
if undupe then
table.insert(undupeitems, v)
end
end
end
local c=#undupeitems
function CountUniqueItems(Items: TStrings): Integer;
var
List: TStringList;
begin
List := TStringList.Create;
List.Duplicates := dupIgnore;
List.Sorted := True;
List.AddStrings(Items);
Result := List.Count;
List.Free;
end;
begin
...
c := CountUniqueItems(items);
...
end.
use List::Util qw(uniq);
my $c = scalar(uniq @items);
c = len({*items})
array = []
for value in items:
if value not in array:
array.append(value)
c = len(array)
c = 0
for index, value in enumerate(items):
if value not in items[index + 1:]:
c += 1
local undupeitems = {}
for _, v in ipairs(items) do
local undupe = true
if #undupeitems == 0 then
table.insert(undupeitems, v)
else
for _, v2 in ipairs(undupeitems) do
if v == v2 then
undupe = false
end
end
if undupe then
table.insert(undupeitems, v)
end
end
end
local c=#undupeitems
function CountUniqueItems(Items: TStrings): Integer;
var
List: TStringList;
begin
List := TStringList.Create;
List.Duplicates := dupIgnore;
List.Sorted := True;
List.AddStrings(Items);
Result := List.Count;
List.Free;
end;
begin
...
c := CountUniqueItems(items);
...
end.