Sort of from a blank state. I code in python and learn other languages, but I’m not super familiar with javascript functions.
It was really just feedback for the video. I felt the map and filter was super clear and great from the video, but I don’t quite understand how reduce is deciding what to remove from the two bowls at the beginning.
Thanks for the feedback. While I can't edit the existing video, I might make a new, hopefully better one.
Map, filter, and reduce are not necessarily javascript functions. They are general concepts which can be found (or implemented) in various languages.
The point of reduce is to run the given function with the given data, repeatedly "reducing" the data. In the video, the function is "mix", which takes two arguments and mixes them together. The data is 3 bowls of fruit.
Reduce takes the function, then takes first two arguments, and passes them to the function. The function returns one piece of data (the mixed stuff), and now reduce passes that one piece together with the remaining third argument to another call of "mix". So in the end we have essentially mixed 3 elements together, even though "mix" accepts only 2 arguments. This is the reduction — a repeated application of some function on arbitrary amount of data.
So:
reduce([A, B, C], mix_fn)
is essentially converted into:
mix(mix(A, B), C)
Hope that helps. Btw, in Python, there is functools.reduce() for this.
I think what I find confusing is that reduce doesn’t result in any actual reduction in the quantity of the vegetables on hand being mixed in the video even though it’s being called reduce. Maybe you could use a bigger bowl to make it clear that none of the elements in the first two bowls is actually being reduced. I was wondering how the function decided to eliminate some of the vegetables lol.
I definitely learned something from watching the video and having the discussion. I think the map function was super informative!
Yeah, I see how this is confusing. I believe it's called reduce because its goal is to reduce a set of values to a single value. It doesn't necessarily mean that the amount of data is reduced.
9 comments
[ 0.22 ms ] story [ 41.5 ms ] threadIt was really just feedback for the video. I felt the map and filter was super clear and great from the video, but I don’t quite understand how reduce is deciding what to remove from the two bowls at the beginning.
Map, filter, and reduce are not necessarily javascript functions. They are general concepts which can be found (or implemented) in various languages.
The point of reduce is to run the given function with the given data, repeatedly "reducing" the data. In the video, the function is "mix", which takes two arguments and mixes them together. The data is 3 bowls of fruit.
Reduce takes the function, then takes first two arguments, and passes them to the function. The function returns one piece of data (the mixed stuff), and now reduce passes that one piece together with the remaining third argument to another call of "mix". So in the end we have essentially mixed 3 elements together, even though "mix" accepts only 2 arguments. This is the reduction — a repeated application of some function on arbitrary amount of data.
So:
is essentially converted into: Hope that helps. Btw, in Python, there is functools.reduce() for this.I think what I find confusing is that reduce doesn’t result in any actual reduction in the quantity of the vegetables on hand being mixed in the video even though it’s being called reduce. Maybe you could use a bigger bowl to make it clear that none of the elements in the first two bowls is actually being reduced. I was wondering how the function decided to eliminate some of the vegetables lol.
I definitely learned something from watching the video and having the discussion. I think the map function was super informative!
I liked and subbed!