Find the largest digit in a number

Write a function named largest_digit that takes an integer n as input and returns the largest digit in n. Use a while loop. Your function should also work for negative integers by considering the digits of abs(n).

Complete the supplied function in Listing 1. Keep its signature and use the checks below it.

Listing 1: Starter function and supplied checks for find the largest digit in a number.
def largest_digit(n: int) -> int:
    # Add code here!
    pass


assert largest_digit(12345) == 5
assert largest_digit(987654321) == 9
assert largest_digit(0) == 0

abs(value) returns its magnitude, so abs(-42) is 42. % gives a division remainder, and // gives the floor of a quotient. For example, 42 % 10 is 2 and 42 // 10 is 4.

assert condition stops a failed check with an AssertionError.