I'm trying to write a program that takes any number of command line arguments, in this case, strings and reverses them, then outputs them to the console. Here is what I have so far:
let CL = process.argv.slice(2);
let extract = CL[0];
function reverseString(commandInput) {
var newString = "";
for (var i = commandInput.length - 1; i >= 0; i--) {
newString += commandInput[i];
}
return console.log(newString);
}
let call = reverseString(extract);
I can't figure out a way to make this work for multiple arguments in the command line such as:
node reverseString.js numberOne numberTwo
which would result in output like this:
enOrebmun owTrebmun
however it works fine for a single argument such as:
node reverseString.js numberOne

CL.join(" ").reverse().let calls = CL.map(reverseString);then log them if you want like:console.log(calls.join("\n"));CL-for (const x in CL) { console.log(reverseString(x)) }return console.log(newString)toreturn newString-console.logdoesn't return anything.