-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ20053.js
47 lines (38 loc) · 896 Bytes
/
BOJ20053.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Solution 1
function solution1(nums) {
let maxNum = Number.MIN_SAFE_INTEGER;
let minNum = Number.MAX_SAFE_INTEGER;
nums.forEach((num) => {
if (maxNum < num) {
maxNum = num;
}
if (minNum > num) {
minNum = num;
}
});
return `${minNum} ${maxNum}`;
}
// Solution 2
function solution2(nums) {
return `${Math.min(...nums)} ${Math.max(...nums)}`;
}
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const t = Number(input[0]);
const arr = input.slice(1);
for (let i = 0; i < t; i++) {
const n = arr.shift();
const nums = arr
.shift()
.split(' ')
.map((value) => Number(value));
console.log(solution1(nums));
}
for (let i = 0; i < t; i++) {
const n = arr.shift();
const nums = arr
.shift()
.split(' ')
.map((value) => Number(value));
console.log(solution2(nums));
}