Recap - 2D Arrays
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 15 of 78.
Challenge
EasyWrite a function named grid_stats with one parameter, grid: a 2D array of integers with at least one cell (declare it as grid: Array). It goes through every cell and returns an array of three numbers, in this order:
- The sum of all the cells
- The largest cell
- How many cells are even
For example, grid_stats([[1, 2], [3, 4]]) returns [10, 4, 2]. The cells can be negative: grid_stats([[-1, -2], [-3, -4]]) returns [-10, -1, 2].
The tests call grid_stats() themselves and show the returned array as 10,4,2. Do not call it and do not print anything.
Try it yourself
func grid_stats(grid: Array):
# 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