TypeScript bootcamp · Lab 29

Median of three

easyArrays10 minLesson: Arrays

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

QuestionHint and solution stay closed until you open them

Read three integers; log the median.

Input. Three integers.

Output. Middle value.

Examples

Example 1
Input
3 1 2
Output
2
Hint
  1. Sort a copy; pick index 1.
Show correct code

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

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