I'm trying to learn node Js, and I came across a few things that I can't figure out, I'm supposed to be able to do the "--filter" command or "filter" and the "--count" command or "count". And I'm supposed to be able to do the combination of both. For example do: "node app.js --filter=ry --count" or "node app.js --count --filter=ry" but for example for the latter it does not work unless filter is placed before count , here is my code.
try {
const cmd = args[2].split("=");
if (cmd[0] === '--filter' || cmd[0] === 'filter') {
if (args.includes('--count') || args.includes('count')) {
filter(cmd[1]);
count();
} else {
filter(cmd[1]);
}
} else if (cmd[0] === '--count' || cmd[0] === 'count') {
if (args.includes('--filter') || args.includes('filter')) {
filter(cmd[2]);
console.log(cmd);
count();
} else {
count();
}
} else {
console.log('Wrong arguments');
}
} catch (err) {
throw err;
}
I tried several solutions, to be able to do --count before filter when I type it in command but I still can't filter and count if the filter is not placed first