为什么我arguments这样使用时会出错?
function sum(){
return arguments.reduce(function(a,b){
console.log(a+b)
return a+b;
},0);
}
sum(1,2,3,4);
Run Code Online (Sandbox Code Playgroud)
错误:
/Users/bob/Documents/Code/Node/hello.js:2
return arguments.reduce(function(a,b){
^
TypeError: Object #<Object> has no method 'reduce'
at sum (/Users/bob/Documents/Code/Node/hello.js:2:19)
at Object.<anonymous> (/Users/bob/Documents/Code/Node/hello.js:8:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:903:3
Run Code Online (Sandbox Code Playgroud)
这是来自Crockford先生的JS讲座.
我是一名刚开始学习 Python 的新程序员,但有一些事情困扰着我,我想改变它。
正如我所见,执行代码时可以从终端删除不需要的路径,我无法弄清楚如何访问 Visual Studio Code launch.json文件,并且 Google 上的所有解释都非常混乱。
我有一个Python字典:
d = {
"config": {
"application": {
"payment": {
"dev": {
"modes": {"credit,debit,emi": {}},
"company": {
"address": {
"city": {"London": {}},
"pincode": {"LD568162": {}},
},
"country": {"United Kingdom": {}},
"phone": {"7865432765": {}},
},
"levels": {"0,1,2": {}},
},
"prod": {"modes": {"credit,debit": {}}, "levels": {"0,1": {}}},
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想将其更改为类似这样的内容(如果值为空{},则将键作为其父项的值)
d = {
"config": {
"application": {
"payment": {
"dev": {
"modes": "credit,debit,emi",
"company": {
"address": {
"city": "London",
"pincode": "LD568162"
},
"country": "United Kingdom",
"phone": "7865432765"
},
"levels": "0,1,2" …Run Code Online (Sandbox Code Playgroud) python tree recursion recursive-datastructures data-structures