|
1 | | - |
2 | | -function main() { |
3 | | - const commands: string[] = process.argv.slice(2) |
4 | | - if (commands.length === 0) { |
5 | | - throw new Error("No command line arguments passed") |
6 | | - } |
7 | | - /* |
8 | | - * Format of the 'args' array: [ |
9 | | - * <COMMAND_NAME_1> <ARG1> <ARG2> .. <ARG N>, |
10 | | - * <COMMAND_NAME_2> <ARG1> <ARG2> .. <ARG N> |
11 | | - *] |
12 | | - * |
13 | | - * The code evaluator will execute this code by using the command |
14 | | - * node main.js 'COMMAND_NAME_1 ARG1 ARG2 ARG3' 'COMMAND_NAME_2 ARG1' |
15 | | - * |
16 | | - * We loop through the list of commands passed in as input arguments and handle each one of them |
17 | | - */ |
18 | | - for (let cmd of commands) { |
19 | | - //arg will have each command passed in the command line argumens |
20 | | - handle(cmd) |
21 | | - } |
| 1 | +/* |
| 2 | + * This is the main entry point for the program. It will parse the input for you. |
| 3 | + * You don't need to change this. |
| 4 | + */ |
| 5 | +function main(): void { |
| 6 | + const input: string[] = process.argv.slice(2); |
| 7 | + if (input.length === 0) { |
| 8 | + throw new Error("No argument passed"); |
| 9 | + } |
| 10 | + const arr: number[] = JSON.parse(input[0]) as number[]; |
| 11 | + const output: number[] = handle(arr); |
| 12 | + console.log(output); |
22 | 13 | } |
23 | 14 |
|
24 | | - |
25 | 15 | /* |
26 | | - * This method should parse each input and assigns it into different variables. |
27 | | - * |
28 | | - * The value of the function parameter "input" will be of the format - "`<COMMAND_NAME_1> <ARG1> <ARG2> .. <ARG N>". |
29 | | - * We split the string and retrieve the input data appropriately into the variable inputListForOneCommand. |
30 | | - * |
| 16 | + * Use this method to write your solution. |
| 17 | + * arr - Is an array of Integers |
31 | 18 | */ |
32 | | -function handle(cmd: string) { |
33 | | - const inputsForOneCommand: string[] = cmd.split(' ') |
34 | | - console.log(inputsForOneCommand) |
35 | | - //TODO: implement the logic to handle each input |
| 19 | +function handle(arr: number[]) { |
| 20 | + // TODO: implement the logic to handle each input and return the final output |
| 21 | + return arr; |
36 | 22 | } |
37 | 23 |
|
38 | | -main() |
| 24 | +main(); |
0 commit comments