loading...

Discussion on: Explain REDUCE Like I'm Five

Collapse
eddieaich profile image
Eddie Aich

Explanation 1
You're on Netflix deciding which movie to watch. You narrow it down to 3 options. You go through each movie and read the summary. Ultimately, you select a movie based on your criteria - let's say duration because it's 11 PM and you want to go to sleep at some point.

You just executed a function on each movie (read the summary, read the duration) and then selected a movie based on your criteria.

Explanation 2
You found an old box of toys in your garage and decide to start selling them online. You pull out a toy one a time and decide how much you want to sell it for. You write down the price on a notebook. You do this for every single toy. At the end, you have a sum total of how much you could potentially make if you sell all of your toys.

You just executed a function on each toy (looked at it, determined how much you want to sell it for) and then at the end, you received a value of how much you could potentially make.

Collapse
devslewis profile image
Seth

The first explanation sounds a lot more like filter. You are more passing a function there that is checking if something is true or not. (Like is it interesting) and returning the one that passed.

Collapse
eddieaich profile image
Eddie Aich

Ah that's true and good catch. I was thinking more along the lines of determining how long a movie is based on the current time and how long it would keep you up. Ignore explanation 1!! =)

Collapse
vonheikemen profile image
Heiker

But think about this: you could implement filter using reduce.