Recap - Remove Duplicates
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 36 of 78.
Challenge
EasyWrite a function remove_duplicates(numbers: Array[int]) -> Array[int] that returns a new array with every number of numbers once, in the order of its first appearance.
For example, remove_duplicates([1, 2, 2, 3, 4, 4, 5]) returns [1, 2, 3, 4, 5], and remove_duplicates([5, 4, 5, 3, 4]) returns [5, 4, 3].
Use a dictionary as a set to remember the numbers you have already seen. You only write the function: Coddy calls it with different arrays and checks what it returns.
Try it yourself
func remove_duplicates(numbers: Array[int]):
# Write code here
pass
All lessons in Logic & Flow
1Strings In Depth
String MethodsSearching in StringsReplace and TrimSplit and JoinRecap - Username Check4Dictionaries Part 2
Nested DictionariesArrays of DictionariesMerging DictionariesCopying DictionariesRecap - Frequency Counter2Advanced Decision Making
Match With VariablesMatch GuardsArray PatternsDictionary PatternsMembership ChecksRecap - Command Parser5Contact Book Application
Display MenuAdd Contact8Student Records Manager
Project OverviewAdd Student3Multi-dimensional Arrays
2D Arrays BasicsAccessing 2D Array ElementsNested Loops with 2D ArraysRecap - 2D ArraysJagged ArraysCommon 2D Array PatternsRecap - Game Board6Sets with Dictionaries
What is a Set?Dictionary as a SetAdding and RemovingUnion and IntersectionSet DifferenceRecap - Remove Duplicates9Advanced Data Aggregation
Summing ValuesFinding Minimum and MaximumCustom SortingRecap - Dictionary SorterPractice on your own: Online GDScript compiler