Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 10, 2023 14:45
Show Gist options
  • Select an option

  • Save codeperfectplus/966855be9650254c22fd38cc4533dce4 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/966855be9650254c22fd38cc4533dce4 to your computer and use it in GitHub Desktop.
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