Skip to content

Commit ef57936

Browse files
committed
codecrafters submit [skip ci]
1 parent 9395c98 commit ef57936

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

β€Žapp/main.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const readline = require("readline");
22

3-
const commands = ["exit", "echo"];
3+
const commands = ["exit", "echo", "type"];
44

55
let terminal = true;
66

@@ -13,14 +13,20 @@ const promptUser = () => {
1313
rl.question("$ ", (answer) => {
1414
const promptArray = answer.split(" ");
1515
const userCommand = promptArray[0];
16-
const userInput = promptArray.slice(1);
16+
const userInput = promptArray.slice(1).join(" ");
1717
if (!commands.includes(userCommand)) {
1818
console.log(`${userCommand}: command not found`);
1919
} else if (userCommand === "exit") {
2020
rl.close();
2121
process.exit(0);
2222
} else if (userCommand === "echo") {
23-
console.log(userInput.join(" "));
23+
console.log(userInput);
24+
} else if (userCommand === "type") {
25+
if (commands.includes(userInput)) {
26+
console.log(`${userInput} is a shell builtin`);
27+
} else {
28+
console.log(`${userInput}: not found`);
29+
}
2430
}
2531
if (terminal) {
2632
promptUser();

0 commit comments

Comments
 (0)