为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

海绵宝宝撒 2019-05-09 22:24:23
//返回每个系列名称,及每个系列一共有多少个课(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求解答和思路
查看完整描述

2 回答

?
烙印99

TA贡献1829条经验 获得超13个赞

functionoutput(arr){
returnarr.map(item=>{
item.lessonCount=item.courses.reduce((total,cur)=>{
total+=cur.lessons.length
returntotal
},0)
deleteitem.courses
returnitem
})
}
                            
查看完整回答
反对 回复 2019-05-09
  • 2 回答
  • 0 关注
  • 371 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信