-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path(easy)mime-type.js
29 lines (23 loc) · 1 KB
/
(easy)mime-type.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
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
const N = parseInt(readline()); // Number of elements which make up the association table.
const Q = parseInt(readline()); // Number Q of file names to be analyzed.
let mimeMap = {};
for (let i = 0; i < N; i++) {
var inputs = readline().split(' ');
const EXT = inputs[0].toLowerCase(); // file extension
const MT = inputs[1]; // MIME type.
mimeMap[EXT] = MT;
}
for (let i = 0; i < Q; i++) {
const FNAME= readline(); // One file name per line.
const group = FNAME.match(/\.([0-9a-z]+)(?:[\?#]|$)/i);
const ext = group && group[1].toLowerCase();
ext && mimeMap[ext] ? console.log(mimeMap[ext]) : console.log('UNKNOWN');
}
// Write an action using console.log()
// To debug: console.error('Debug messages...');
// For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
//console.log('UNKNOWN');