我坚持要解决这个问题。转换下面的数组
var input = [
'animal/mammal/dog',
'animal/mammal/cat/tiger',
'animal/mammal/cat/lion',
'animal/mammal/elephant',
'animal/reptile',
'plant/sunflower'
]
Run Code Online (Sandbox Code Playgroud)
到 json 对象
var expectedResult = {
"animal": {
"mammal": {
"dog": true,
"cat": {
"tiger": true,
"lion": true
},
"elephant": true
},
"reptile": true
},
"plant": {
"sunflower": true
}
}
Run Code Online (Sandbox Code Playgroud)
我可以申请哪种数据结构和算法?谢谢
我是这个Promise对象的新手。当我运行下面的代码时NodeJS
function solution(num){
return getData(num).then(getMax);
}
function getData(num){
return Promise.resolve({
first: 80 * num,
second: 30 * num
});
}
function getMax(numbers){
return Promise.resolve(Math.max(...numbers));
}
solution(10)
Run Code Online (Sandbox Code Playgroud)
我面对错误
(node:7814) UnhandledPromiseRejectionWarning: TypeError: Found non-callable @@iterator at getMax
你能帮我修一下吗?谢谢