Conversation
glpuga
left a comment
There was a problem hiding this comment.
Good work, a couple of questions!
| fib += num | ||
|
|
||
| self.assertEqual(__, fib) | ||
| self.assertEqual(15, fib) |
There was a problem hiding this comment.
Weird, but the name of the variable suggests a Fibonacci sum, but the algorithm is just the addition of the numbers xD.
|
|
||
| even_numbers = filter(is_even, seq) | ||
| self.assertEqual(__, even_numbers) | ||
| self.assertEqual([2, 4, 6], even_numbers) |
There was a problem hiding this comment.
In your words, what's the difference between filter and map?
There was a problem hiding this comment.
map applies the function in all members of the iterator, in contrast, filter do a comparison with the members and if that result is true, it's part of the final output.
| # Describe in your own words what reduce does. | ||
|
|
||
|
|
||
| # Apply the function to every member of the list, the final return is what the final iteration of the function outputs |
There was a problem hiding this comment.
Yeah, but it's a bit more specific than that, right? how does it differ from map?
There was a problem hiding this comment.
The way in which reduce works and differs from is that it receives a function and a sequence(just as map) but it returns just a single value.
The way that this value is calculated is by taking the first two members of the sequence and then executing the function, after that, the result of that first execution is used with the next value of the sequence, this process gets repeated until the last member of the sequence is taken to account.
Completed and ready for review!