Skip to content

Commit 4664186

Browse files
author
Himanshu Dubey
committed
chore: updated
1 parent ebb427b commit 4664186

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
This is a skeleton project structure which will help you start solving the problem right away.
44

55
## Tools available to you.
6+
67
- Node.js
78

89
## How to build your solution
910

1011
- Run `npm ci --include=dev` to install the dependencies.
1112
- Run `tsc --project tsconfig.json` to compile the typescript code.
1213

13-
## Running the project
14+
## Running the project
15+
16+
- After building your solution as per [How to build your solution](#how-to-build-your-solution) you can now run the `main.js` against inputs.
17+
- To run, issue the command `cd dist && node main.js '[...]'` where
1418

15-
- After building your solution as per [How to build your solution](#how-to-build-your-solution) you can now run the `main.js` against inputs.
16-
- To run, issue the command `cd dist && node main.js '[cmd [options...]' 'cmd [options...]'...]` where
17-
- **cmd** is a valid problem specific command.
18-
- **options** are optional **cmd** specific options.
19+
- **[...]** is a valid int arr.
20+
-
1921

20-
Example: `cd dist && node main.js 'ADD APPLE 2' 'ADD ORANGE 3' 'SHOW'` <br>
22+
Example: `cd dist && node main.js '[1, 2, 3]'` <br>
2123

22-
Note: Each full command should be wrapped in single quotes(').
24+
Note: Each full command should be wrapped in single quotes(').
2325

24-
## Checking for correctness
26+
## Checking for correctness
2527

26-
- You can click on the `Run IO` button from the interview application, which will run your solution against some preconfigured inputs and show you the output.
28+
- You can click on the `Run IO` button from the interview application, which will run your solution against some preconfigured inputs and show you the output.

src/main.ts

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
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);
2213
}
2314

24-
2515
/*
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
3118
*/
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;
3622
}
3723

38-
main()
24+
main();

0 commit comments

Comments
 (0)