-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone.js
More file actions
41 lines (32 loc) · 707 Bytes
/
Copy pathone.js
File metadata and controls
41 lines (32 loc) · 707 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
36
37
38
39
40
41
import { readFile } from 'fs/promises';
// 1a
// async function init() {
// const input = await readFile('one.txt', 'utf8');
// const data = input.split('\n').map((d) => parseInt(d));
// let last,
// counter = 0;
// data.forEach((d) => {
// if (last) {
// if (d > last) {
// counter++;
// }
// }
// last = d;
// });
// console.log(counter);
// }
// 1b
async function init() {
const input = await readFile('one.txt', 'utf8');
const data = input.split('\n').map((d) => parseInt(d));
let counter = 0;
data.forEach((d, i) => {
if (i > 2) {
if (d > data[i - 3]) {
counter++;
}
}
});
console.log(counter);
}
init();