-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabc.js
More file actions
54 lines (37 loc) · 904 Bytes
/
abc.js
File metadata and controls
54 lines (37 loc) · 904 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
42
43
44
45
46
47
48
49
50
51
52
53
54
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const dict = {
A:0,
B:0,
C:0
};
const comparator_int_ascending = (a,b) => a-b;
// this function excepts num array as parameter
// and return sorted array in ascending order
function sort_int(arr = [1, 2, 3]){
return arr.sort(comparator_int_ascending);
}
function map_char_to_int(arr){
let index = 0;
for (const key in dict) {
dict[key] = arr[index];
index++;
}
}
function print_dict(keys = ['A', 'B', 'C']){
for (const key of keys) {
process.stdout.write( dict[key].toString()+' ' );
}
}
let sorted;
rl.on('line', line =>{
if(!sorted){
sorted = sort_int(line.split(' ').map( x => parseInt(x)));
map_char_to_int(sorted);
} else {
print_dict(line.split(''));
}
});