Practice: A Tiny CLI
Parse arguments and print results. Here we simulate argv.
Example
const argv = ["add", "2", "3"];
const [cmd, ...nums] = argv;
const n = nums.map(Number);
const ops = { add: (a, b) => a + b, mul: (a, b) => a * b };
console.log(ops[cmd] ? ops[cmd](...n) : "unknown command");Result
5
Exercise
Spread arguments.
ops[cmd](n)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.