-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11536_v2.js
More file actions
35 lines (28 loc) · 757 Bytes
/
11536_v2.js
File metadata and controls
35 lines (28 loc) · 757 Bytes
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
const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
const isIncreasing = (names) => names.every((name, index) => {
if (index === 0) return true;
return names[index - 1] < name;
});
const isDecreasing = (names) => names.every((name, index) => {
if (index === 0) return true;
return names[index - 1] > name;
});
const solve = (names) => {
if (isIncreasing(names)) console.log('INCREASING');
else if (isDecreasing(names)) console.log('DECREASING');
else console.log('NEITHER');
};
let isFirstLine = true;
const names = [];
rl.on('line', (line) => {
if (isFirstLine) {
isFirstLine = !isFirstLine;
return;
}
names.push(line.trim());
}).on('close', () => {
solve(names);
});