File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ function duplicateCharacterCounter (word )
2+ local hasDuplicates = false ;
3+
4+ -- Empty or no input validation
5+ if word == " " or word == nil then
6+ print (" Usage: please provide a string" )
7+ return
8+
9+ -- Check for duplicates validation
10+ elseif (string.len (word ) >= 1 ) then
11+ local myTable = {}
12+ local duplicateList = {}
13+
14+ for i = 1 , string.len (word ) do
15+ local char = string.sub (word , i , i )
16+ if (myTable [char ]) then
17+ myTable [char ] = myTable [char ]+ 1
18+ hasDuplicates = true
19+
20+ else
21+ myTable [char ] = 1 ;
22+ table.insert (duplicateList , char )
23+ end
24+ end
25+ for _ , char in ipairs (duplicateList ) do
26+ if myTable [char ] > 1 then
27+ print (char .. " : " .. myTable [char ])
28+ end
29+ end
30+ end
31+
32+ -- No duplicates validation
33+ if not (hasDuplicates ) then
34+ print (" No duplicate characters" )
35+ end
36+ end
37+
38+ duplicateCharacterCounter (arg [1 ])
You can’t perform that action at this time.
0 commit comments