-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (54 loc) · 1.41 KB
/
index.js
File metadata and controls
65 lines (54 loc) · 1.41 KB
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
55
56
57
58
59
60
61
62
63
64
65
const terminal = require( './terminal' );
const lines = [];
const used = process.argv[ 2 ] || 'exo7';
const exo7 = require( './utils/exo7' );
const exo8 = require( './utils/exo8' );
const exo9 = require( './utils/exo9' );
console.log( 'Enter your data' );
terminal.prompt();
terminal.on( 'line', ( data ) => {
let n = 0;
if ( lines.length ) {
/**
*
* the first line give the
* number of test case
*/
n = parseInt( lines[ 0 ] );
lines.push( data.slice( 2 ) );
} else {
lines.push( data );
}
const
needed = lines.length - 1;
/**
*
* here we have to manage when
* the terminal will stop to receive
* terminal data
*/
if ( needed > 0 ) {
if ( used === 'exo7' && needed === n ) {
terminal.close();
return;
} else if ( used === 'exo8' && needed === n * 2 ) {
terminal.close();
return;
} else if ( used === 'exo9' ) {
}
}
terminal.write( '> ' );
} );
terminal.on( 'close', () => {
switch( used ) {
case 'exo7':
exo7.call( {}, lines.slice( 1 ) );
break;
case 'exo8':
exo8.call( {}, lines.slice( 1 ) );
break;
case 'exo9':
exo9.call( {}, lines.slice( 1 ) );
break;
}
} );