Skip to content Skip to sidebar Skip to footer

When I Run My `node File.js 1 23 44` Script, It Doesn't Prinout Anything

When I run node file.js 1 23 45, it's supposed to printout One TwoThree FourFive but for some reason it's not printing out. I think the script runs fine because I get no issues run

Solution 1:

You defined the Map and the method toDigits, but are not actually calling the method. You can do that by adding toDigits(...). To parse the command line arguments you can use process.argv. This will give you something like

[
  'node',
  '/path/to/script/index.js',
  '1',
  '23',
  '45'
]

Which you can use e.g., with process.argv.slice(2)in your code.

const numbersMap = newMap([
  [ "0", "Zero" ],
  [ "1", "One"],
  [ "2", "Two"],
  [ "3", "Three"],
  [ "4", "Four"],
  [ "5", "Five"],
  [ "6", "Six"],
  [ "7", "Seven"],
  [ "8", "Eight"],
  [ "9", "Nine"]
]);

functiontoDigits (integers) {
  const r = [];

  for (const n of integers) {
    const stringified = n.toString(10);
    let name = "";

    for (const digit of stringified)
      name += numbersMap.get(digit);
    r.push(name);
  }

  console.log(r.join());
}

// You can parse command line arguments like this:const integers = process.argv.slice(2);

// and then pass them ontoDigits(integers);

Post a Comment for "When I Run My `node File.js 1 23 44` Script, It Doesn't Prinout Anything"