-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path13.js
More file actions
30 lines (22 loc) · 734 Bytes
/
13.js
File metadata and controls
30 lines (22 loc) · 734 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
let getResult = (data) => {
let parse_ints = str => {
return str.split(' ').filter(val => val != '').map(val => parseInt(val.trim()));
}
let [n, goal] = parse_ints(data[0]);
let new_arr = [];
for(let i = 1; i <= n; i++) {
let num = data[i].trim().replace(/[^0-9]/gi, '');
if (num.length>10){
num = num.substr(num.length-10);
}
new_arr.push([data[i].trim(), parseInt(num)]);
}
new_arr.sort((a,b) => a[1] - b[1]);
return new_arr[goal-1][0];
}
const { count } = require('console');
const fs = require('fs');
let fileContent = fs.readFileSync("input.txt", "utf8");
const data = fileContent.toString().trim().split("\n");
const result = getResult(data);
fs.writeFileSync("output.txt", result.toString());