• + 0 comments

    IF YOU HAVE THE KNOWLEDGE OF MAP,FILTER,SORT,FIND ETC THEN IT WILL BE SUPER HELPFUL FOR YOU

    More concise and clean code

    function getSecondLargest(nums) {
        // Complete the function
        // sorting the array in descending order [6,6,5,3,2]
        nums.sort((a, b) => b - a);
        
        // using find method to search for the first number in nums that is not equal to nums[0]
        let secondLargest = nums.find(value => value !== nums[0]);
        
        // Return the second largest number
    
    return secondLargest;
    

    }