We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
IF YOU HAVE THE KNOWLEDGE OF MAP,FILTER,SORT,FIND ETC THEN IT WILL BE SUPER HELPFUL FOR YOU
More concise and clean code
functiongetSecondLargest(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]letsecondLargest=nums.find(value=>value!==nums[0]);// Return the second largest number
return secondLargest;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 3: Arrays
You are viewing a single comment's thread. Return to all 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
}