今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Advanced methods 2
(light upbeat music) - [Instructor] For this challenge, we've been given an array of sales. And we have three sales in here, and we want to know, what are our total sales? If we added each of these up, what would we get? For this challenge, we're actually going to use an array method called reduce. I mentioned filter was one of my favorites. Reduce is also one of my favorites. But I will say, I use it all the time, and I feel like I often have to reference documentation to make sure that I set it up correctly. So if you find yourself in the same boat, don't worry about it. I think it happens to a lot of folks. So no big deal. The fact is, you knew to reach for it, and that's the important part. So the first thing that I'm going to do, very similar to what we've done before, reduce is going to return a new value. And that's going to be dependent on what we call the accumulator. And we'll get into that here in a second. So I'm going to return sales, our array that exists, and reduce…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。