js使用数组重组方法返回课程名称及返回课程数量

//返回每个系列名称,及每个系列一共有多少个课(lesson的总数);
问题出现的环境背景及自己尝试过哪些方法
相关代码
constSeries=[{
name:'Web',
courses:[{
name:'HTML',
lessons:[{
name:'HTMLLesson1'
},{
name:'HTMLLesson2'
},{
name:'HTMLLesson3'
}]
},{
name:'CSS',
lessons:[{
name:'CSSLesson1'
},{
name:'CSSLesson2'
},{
name:'CSSLesson3'
},{
name:'CSSLesson4'
}]
},{
name:'JavaScript',
lessons:[{
name:'JavaScriptLesson1'
},{
name:'JavaScriptLesson2'
}]
}]
},{
name:'PHP',
courses:[{
name:'Linux',
lessons:[{
name:'LinuxLesson1'
},{
name:'LinuxLesson2'
}]
},{
name:'MySQL',
lessons:[{
name:'MySQLLesson1'
},{
name:'MySQLLesson2'
},{
name:'MySQLLesson3'
},{
name:'MySQLLesson4'
}]
},{
name:'Nginx',
lessons:[{
name:'NginxLesson1'
},{
name:'NginxLesson2'
},{
name:'NginxLesson3'
},{
name:'NginxLesson4'
}]
}]
}]
functionoutput3(Series){
//...
}
output3(Series)
题目来源及自己的思路
aitschool求解答和思路
海绵宝宝撒
浏览 372回答 2
2回答

烙印99

functionoutput(arr){returnarr.map(item=>{item.lessonCount=item.courses.reduce((total,cur)=>{total+=cur.lessons.lengthreturntotal},0)deleteitem.coursesreturnitem})}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript