Created
September 10, 2023 14:45
-
-
Save codeperfectplus/966855be9650254c22fd38cc4533dce4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getSecondLargest(nums) { | |
| // Complete the function | |
| let max1 = 0; | |
| for (const e of nums) { | |
| if (max1 < e) { | |
| max1 = e; | |
| } | |
| } | |
| let max2 = 0; | |
| for(const e of nums) { | |
| if(max2 < e && e < max1) { | |
| max2 = e; | |
| } | |
| } | |
| return max2 | |
| } | |
| const nums = [2,3,6,6,5]; | |
| console.log(getSecondLargest(nums)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment