Recap - Number Processor
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 65 of 78.
Challenge
EasyWrite a function named process_numbers that takes an array of whole numbers, numbers, and returns a new array:
- First drop every number that is
0or negative. - Then double the even numbers that are left and triple the odd ones.
Keep the original order. Use filter() and map(), and no loop. For example, process_numbers([-4, 0, 5, 2, 8, -3, 7]) returns [15, 4, 16, 21].
The tests call process_numbers() themselves. Do not call it, and do not print anything.
Try it yourself
func process_numbers(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 Student11Higher-Order Functions
The map MethodThe filter MethodThe reduce Methodany and allRecap - Email ValidatorRecap - Number Processor3Multi-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