Remove Duplicates from array (return unique values)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Remove Duplicates from array (return unique values)

14 Nov 2017, 11:37

Code: Select all

RmvDuplic(object) {
secondobject:=[]
Loop % object.Length()
{
	value:=Object.RemoveAt(1) ; otherwise Object.Pop() a little faster, but would not keep the original order
	Loop % secondobject.Length()
		If (value=secondobject[A_Index])
    		Continue 2 ; jump to the top of the outer loop, we found a duplicate, discard it and move on
	secondobject.Push(value)
}
Return secondobject
}
For AHK v2:

Code: Select all

RmvDuplic2(object) {
secondobject:=[]
Loop object.Length()
{
	value:=Object.RemoveAt(1)
	Loop secondobject.Length()
		If (value=secondobject[A_Index])
    		Continue 2 ; jump to the top of the outer loop, we found a duplicate, discard it and move on
	secondobject.Push(value)
}
Return secondobject
}
By Exaskryz
try it and see
...
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: Remove Duplicates from array (return unique values)

14 Nov 2017, 11:40

I might come up with better versions with other suggestions from the linked thread. I am also planning to work on a custom class that would do this. (Inspired by Helgef)
try it and see
...

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: ConnorMcLoud and 153 guests