Second Largest — Edge Case

Node.js Published Updated 0 Views Verified
Node.js Coding Challenge — Second Largest (Edge Case). You are building a small JavaScript/Node.js utility. Make the solution safe for empty input, zero, negative values, duplicates or boundary values where applicable. Explain the logic briefly and provide runnable Node.js code. The solution must avoid accidental string-number concatenation and should behave predictably for normal input.
Looking for the latest Sarkari Result 2026 updates? Check the latest government exam results, merit lists and result updates on Sarkari Resultess.
Sarkari Resultess
Questions & Answers

Answer & Explanation

4 Answers
Verified Correct Answer

Correct Code / Solution

function secondLargest(arr) { return [...new Set(arr)].sort((a,b)=>b-a)[1]; } console.log(secondLargest([9,2,9,7,5]));
Additional Explanation
This solution implements Second Largest using standard JavaScript/Node.js syntax. Keep numeric inputs as numbers, validate boundary cases when the problem requires it, and return a value from reusable functions instead of mixing calculation with output.
Sarkari Resultess
Editorial Answer 1
Verified Correct Answer

Correct Code / Solution

function secondLargest(arr) { return [...new Set(arr)].sort((a,b)=>b-a)[1]; } console.log(secondLargest([9,2,9,7,5]));
Additional Explanation
This solution implements Second Largest using standard JavaScript/Node.js syntax. Keep numeric inputs as numbers, validate boundary cases when the problem requires it, and return a value from reusable functions instead of mixing calculation with output.
Sarkari Resultess
Editorial Answer 2
Verified Correct Answer

Correct Code / Solution

function secondLargest(arr) { return [...new Set(arr)].sort((a,b)=>b-a)[1]; } console.log(secondLargest([9,2,9,7,5]));
Additional Explanation
This solution implements Second Largest using standard JavaScript/Node.js syntax. Keep numeric inputs as numbers, validate boundary cases when the problem requires it, and return a value from reusable functions instead of mixing calculation with output.
Sarkari Resultess
Editorial Answer 3
Verified

Possible but Incorrect Code

function secondLargest(arr) { return String([...new Set(arr)].sort((a,b)=>b-a)[1]; } console.log(secondLargest([9,2,9,7,5]));
Additional Explanation
यह option जानबूझकर एक common bug/unsafe approach दिखाता है। इसे production solution के रूप में इस्तेमाल करने से पहले variable scope, async flow, module path, validation, error handling और security checks verify करें। ऊपर दिए गए correct option से exact difference compare करें.
Sarkari Resultess
Editorial Answer 4