Isn't more simple like this? getSecondLargest = (nums) => { if (!nums || !nums.length) return; if (nums.length < 2) return nums[0]; return nums.sort().reverse()[1...