Tsallaka zuwa abun ciki
Justice Tech School

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

Why map(Number)?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.