notexOPENOverview
Notex/Languages/Practice: functions, parameters, and return values
03.09LESSON 09 OF 18 · 1 MIN READ

Practice: functions, parameters, and return values

Always free to read

These exercises let you experiment with writing functions of your own.

  1. Write a function called subtract that takes in two int parameters and returns an int. Call this function from main with several values and print out the result.

  2. Write a function named minMax that takes in 0 or more int values and returns three results: the smallest number, the largest number, and an error. If no values are passed to minMax, return an error using errors.New. Otherwise, the returned error should be nil. Call it from main three ways: with no arguments, with several arguments, and with an []int.

  3. Write a function split that accepts a string and a separator and returns the nonempty parts. Review its parameter handling, return values, and control flow, and explain how each choice improves clarity.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K