1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Julia

Exercise

Multiple dispatch

Multiple dispatch is one of Julia's significant advantages, providing flexibility and speed benefits to your Julia programs. Remember, multiple dispatch allows you to run a different method based on the type of the argument passed into a function.

The example in the video used multiple dispatch to return a different value depending on whether the argument type was a string or not.

function add_values(x, y)
    x + y
end

function add_values(x::String, y::String)
    x * y
end

Instructions

100 XP
  • Create a function largest_value which:
    • if the input is String, use map to map the length function to each argument (x, y, z).
    • if the input is Bool, simply return the arguments.
    • if the input is any other type, get the maximum of all values using maximum.
  • Remove the commented-out lines at the bottom (the test cases) and ensure that the logic makes sense!