大佬教程收集整理的这篇文章主要介绍了当我运行我的 `node file.js 1 23 44` 脚本时,它没有打印任何内容,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我运行 node file.Js 1 23 45
时,它应该打印出 One TwoThree FourFive
但由于某种原因它没有打印出来。我认为脚本运行良好,因为我在运行它时没有遇到任何问题,但它只是没有打印出任何内容。我错过了什么还是我完全错了?
const numbersmap = new Map([
[ "0","Zero" ],[ "1","One"],[ "2","Two"],[ "3","Three"],[ "4","Four"],[ "5","Five"],[ "6","Six"],[ "7","Seven"],[ "8","Eight"],[ "9","Nine"]
]);
function toDigits (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());
}
您定义了 Map 和方法 toDigits
,但实际上并未调用该方法。您可以通过添加 toDigits(...)
来实现。
要解析命令行参数,您可以使用 process.argv
。这会给你类似的东西
[
'node','/path/to/script/index.js','1','23','45'
]
您可以在代码中使用例如 process.argv.slice(2)
。
const numbersmap = new Map([
[ "0","Zero" ],[ "1","One"],[ "2","Two"],[ "3","Three"],[ "4","Four"],[ "5","Five"],[ "6","Six"],[ "7","Seven"],[ "8","Eight"],[ "9","Nine"]
]);
function toDigits (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 on
toDigits(Integers);
以上是大佬教程为你收集整理的当我运行我的 `node file.js 1 23 44` 脚本时,它没有打印任何内容全部内容,希望文章能够帮你解决当我运行我的 `node file.js 1 23 44` 脚本时,它没有打印任何内容所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。