Menu
CoddyTech

Recap - 2D Arrays

Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 15 of 78.

challenge icon

Challenge

Easy

Write 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:

  1. The sum of all the cells
  2. The largest cell
  3. 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

Practice on your own: Online GDScript compiler