Largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

Comment used to generate the code:

function that finds the largest prime factor of a given number

function largestPrimeFactor(num: number): number {

      let largestPrime: number = 0;

      let i: number = 2;

      while (i <= num) {

        if (num % i === 0) {

          largestPrime = i;

          num = num / i;

        } else {

          i++;

        }

      }

      return largestPrime;

    }

Thoughts:

This is the last one I had solved myself before copilot was a thing, another while loop from copilot, but it does the job.