TypeScript bootcamp · Lab 48

Second largest

mediumArrays12 minLesson: Arrays

Read the question, write TypeScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Print second largest among distinct ints.

Examples

Example 1
Input
3 1 8 2
Output
3
Hint
  1. sort unique desc
Show correct code

Peek only after you have tried. You can still Check your own version.

const nums: number[] = [...new Set(readLine().trim().split(/\s+/).map(Number))].sort((a, b) => b - a);
console.log(nums[1]);
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.