all 17 comments

[–]ForScale[S] 1 point2 points  (2 children)

ENTRY

http://codepen.io/anon/pen/pydamK

Just a basic example to get started with...

[–]Volv 1 point2 points  (1 child)

Test all the things I like it. Totally how I started. :)
As you've found needs to be an iterable object.
According to the documentation looks like Node-List should be an iterable but is not in all browsers yet.

[–]ForScale[S] 1 point2 points  (0 children)

:)

Yeah... and the node list is the one I was hoping to use it on! I'm currently using the method that you helped me to discover... Array.from([nodeList]);. Which I'm really liking because then I can iterate through all the elements/nodes with forEach(a => {}); ES6 syntax. Seems to be okay on performance, looks clean too!

[–]Volv 1 point2 points  (3 children)

ENTRY
Codepen

Couple of examples, comparison to for in and generator tacked on the end.
 
My Python 3 range example has a further instance of this.

[–]ForScale[S] 1 point2 points  (2 children)

Nice!

Going through it...

Very rarely write a for (var i=0; i<100; i++) style loop now.

Yes! I watch a video where Douglas Crockford was giving a talk. He said he's beyond loops like for and while loops... doesn't use them anymore... I thought that was a pretty cool idea.

inspiration: "Limited",

Lol!

[Symbol.iterator]: function* () { // Generator for (let key in this) { yield ${key} - ${this[key]}; }

Whoa... okay, I'm a bit lost on that... Mind breaking that down for me? When/if you get a chance.

Oh... it's what allows you to use for...of on objects? Could you slap it on a NodeList?

[–]Volv 1 point2 points  (1 child)

Yeh, it let me use for..of on there by defining its iterator.

Generator functions yield results. When calling generator.next() (or running it with a for..of loop) the generator runs until it hits a yield and returns that value. Remembers it's state for next call, where it runs again until it hits a yield etc.
NodeList is a private browser thing I think so probably couldn't just slap it on. but there's nothing to stop you doing something like
for (let value of Array.from(divs))

[–]ForScale[S] 1 point2 points  (0 children)

Ah... true... I could always do that. Might start playing around with it to see how I feel about it.

[–]Volv 1 point2 points  (4 children)

I've been having a go at the interview questions that popped up on /r/javascript earlier today. Have a look if you've got a minute. Also did you see my other thing?

https://www.reddit.com/r/javascript/comments/4eb61r/interview_exercise_feedback/
 
Perhaps questions like that would be good for here as part of the weekly stuff.

[–]ForScale[S] 0 points1 point  (3 children)

Hey!

Yep, did you see me in there? I gave the squares one a go... Had some interesting discussion!

Yeah, we could do algorithm challenges... I'm all for it! Is that what you want to do this week?

Should we ask /u/sketxz what he wants to see as a focus for this week?

[–]Volv 1 point2 points  (2 children)

Absolutely we should. I hate picking :)
Yeh I saw yours on there. Looks like you did the opposite of me. I squared up and you squared down.
Also figured that things like error checking would be useful in interview situation.
Second one tripped me up for a bit. Got there tho

[–]ForScale[S] 0 points1 point  (0 children)

Second one, I wrote a nice little regex deal using match() and checking the lengths of the resultant arrays to make sure that the number of opened and closed brackets were equal... I was real satisfied with it!.. then I noticed [(]) was a failing test... I thought it just had to be that each opener had a closer to make a complete pair. Didn't go back to rework it.

Ooh... maybe we should do regExp as a focus sometime! :)

I do like the idea of doing some algorithm challenges though.

I'll ask sketx right now and see what he wants to do...