-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exercise #2 #2
Comments
This doesn't feel like much of a success as it took me so much trial and error to get there but https://github.com/CLTPayne/reduce/blob/master/map1.js |
Well you landed on the right idea! My only feedback is that you don't need to destructure the params. You actually just restructure them again when you pass them to
I also renamed So let's dive into how you felt it was a process of trial-and-error. This is quite important since the whole idea is to give you a new way to think about stuff. I'd love to hear what you found opaque or troublesome. You did the right thing in the end. Does it make sense to you now? The way I like to think of it is that reduce abstracts general list computation and the others (map, etc) use that abstraction to achieve more specific things with lists. The fact that you wanted to destructure the collection passed to Okay so I've just info-dumped on you a bit. Shall we set you up with another exercise? I'll make it a two-parter if you're keen. We'll keep the first exercise in a similar space so you can rework the same ideas a bit. The second part will be more challenging. Maybe let's grab a call one evening before you tackle part two? As always, please feel free to ask questions to challenge or clarify anything I've said. |
Hmmmmm, regarding the destructuring of the array in to On the naming of the function that is passed in as In your version, does For the trial and error process - initially I was quite fixated on the idea that I needed to create the new array (i.e. to stop the reduce returning a single "reduced" value from the array) in the 3rd param position where the empty array should be passed in (instead of the default |
destructuring: ah I think I see what you mean. No you don't need to worry about that. The param var assignment will happen inside callbacks: yeah, something like that. I won't make too strong an assertion about what the 'correct' definition of a callback is but I do think it's important to distinguish higher-order functions from their idiomatic application in JavaScript. JS callbacks are used to get around the fact that you're in a non-blocking, asynchronous runtime. You know how you get param naming: yep, trial-and-error: Ah okay yeah that makes sense. And yep, I think it's part of the deal with this stuff. It wouldn't be useful if we weren't learning! To maybe set the scene on this whole set of exercises a bit more... I don't really expect you to go out and write code like this immediately. In fact please don't use primitive recursion lightly! Don't use it at all in most languages. All I'm trying to do is make a little piece of your brain click into a new mode of thought. That will grow on its own over time and you'll need to see for yourself where it fits and how it can help you. To put it in context, I did some of this stuff in Haskell about ten years ago when I was still working in Ruby. After that it still took years for me to grasp FP 'properly' and of course I'm still learning. Also, if you're not using a real functional language (and the vast majority of languages aren't) then these concepts can only lend a flavour to your code. You can't adopt this entirely if the language doesn't like it. But subtle things will become tighter and cleaner in any language and hopefully you'll rely on state just a little bit less. That's enough. Don't put too much pressure on yourself and trust that paradigmatic stuff like this will take a life of its own. It's all about planting a seed that allows you to think differently. Time will do the rest. You're getting this stuff in early! |
Well done with reduce!! (high five)
The next exercise is simpler. It builds on the previous one.
Reduce provides the conceptual foundation for all recursive list computation. Your next few tasks will be to set about proving this. I've heard people say that anything can be computed with reduce. I think this is hyperbolic but still, it's a strong endorsement.
First up: implement
myMap
using only a single call tomyReduce
. Your whole function body can only bereturn myReduce(_______);
It's all about the parameters you pass in.Unfortunately I think you will need to use an array method. Just be sure that whatever you use is non-destructive. We're still not allowed to mutate state.
The text was updated successfully, but these errors were encountered: