Write largestNumber(nums) that returns the largest number in the array nums.
- If
numsis empty, returnnull. - Numbers can be negative, and the same value can appear more than once.
- Don't use
Math.maxor.sort. Look at the numbers yourself.
Input: nums = [3, 9, 2, 7]
Output: 9
Input: nums = [-5, -2, -8]
Output: -2All negative: the answer is the one closest to zero.
Input: nums = []
Output: null