DEV Community

Cover image for I have no idea what I'm doing, but here Goes #3 IT WORKS!!

I have no idea what I'm doing, but here Goes #3 IT WORKS!!

jamonjamon profile image Jaimie Carter ・2 min read

Phew! It actually works. Well, very roughly.

If you've not been following along: 1. Shame on you. 2. To learn Node, I've decided to build an API that automatically chases freelance work for me.

So where were we? trying to get anything out of Google Calendar and make a JSON. That was done, the only problem was - the way it iterated changed the data enough to be a pain when that same data needed to be interpreted. So the challenge was to leave to data extracted by the Google API unchanged, and change it when it needed to be processed, without destroying the original object/s. That way, any part of it can be used in any way, as required. Don't know if that's the right approach, but if felt good to me. And that's all that's important, right?

The github repo has the files.

The major nightmare I had was understanding the function below. I thought it returned and array... but it wasn't was it? It was iterating (wasn't it?) through every event and pushing them/console.logging them one at a time. I think? Don't mistake my confusion for confusion. Sheer terror is a better description. Anyways, I figured that if I pushed them into an array, that might be an idea, and it seemed to work. I'll take that.

    if (events.length) {   , i) => {
        const start = event.start.dateTime ||;
        cleanDate = start.slice(5, 10);
        //console.log(`${start} - ${event.summary}`);

From there I just needed to manipulate the data, to group days with months and then write an if statement to send string/s when conditions were met. And hey presto! A robot!

I showed it to one of my broadcast friends, and he LOST HIS MIND. "NO WAY! It can do that??"

Yes, Simon. Yes. It. Can. Simon now thinks I'm a genius. I'll take that. It's all about the bullshit factor, isn't it?

Closing shout out:
On the last post I got some great advice from Neil Green. Many thanks for the tips, they were greatly appreciated. The debugger in VScode has blown my mind. Woah!!! How good is a bit of degugging??!!!

Next up: Join this to gmail, and send an email. Oooooooooo. Fun times ahead.

For those that haven't been playing along:
Episode 0
Episode 1
Episode 2

Discussion (4)

Editor guide
jamonjamon profile image
Jaimie Carter Author

Thanks for this advice, it's been valuable. Yes, the magic numbers would be a pain: I'd hate to see random numbers that aren't random, then try to figure out their meaning. I'll change that.

To be honest, I'm still baffled with Every explanation of it refers to creating a new array with manipulated elements from a source array, if that explanation makes sense. In this case, I don't understand why it works. Is the function in my code an iteration, or is it an array, or both? I can't see the actual correlation between the MDN definition and what is happening in this code. It just works. Which is great, don't get me wrong, but I really need to understand the (in broadcast terms) signal flow - what goes from where to where and what happens to it between those points. What is the pattern?

Oh and the debugger. Wow. You can see step by step what is happening with any particular object and how it fits in with stack and when in the process surrounding objects are populated/defined/undefined. So good. Need to dig further into this.

Again, many thanks for the advice, it is appreciated.

Unfortunately for the] next week, I'm slammed with work, and won't have a whole lot of time to devote to this project. Maybe I'll get the gmail API connected.

jamonjamon profile image
Jaimie Carter Author

Ahhh. I get where the original array comes I to it. Combined with an incomplete understanding of arrow functions, is what pushed me into the void. Thanks.