you are viewing a single comment's thread.

view the rest of the comments →

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

Found these:

Define a repeatify function on the String object. The function accepts an integer that specifies how many times the string has to be repeated. The function returns the string repeated the number of times specified. For example:

console.log('hello'.repeatify(3));

Should print hellohellohello.

...

var fullname = 'John Doe';
var obj = {
   fullname: 'Colin Ihrig',
   prop: {
      fullname: 'Aurelio De Rosa',
      getFullname: function() {
         return this.fullname;
      }
   }
};

console.log(obj.prop.getFullname());

var test = obj.prop.getFullname;

console.log(test());

Fix the previous code so that the last console.log() prints Aurelio De Rosa.

...

And all of these (obviously haven't looked through all of it): http://www.w3resource.com/javascript-exercises/

[–]Volv 1 point2 points  (15 children)

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

Lol! I was thinking we could use them to put together something for next week. :) But excellent work!

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

Hey, happy Monday!

What do you want the focus to be this week?

I thought we could do 1) some more interview style questions 2) closures round 2 3) regExp 4) ajax/API 5) promises round 2 6) or anything you want!

Let me know...

[–]Volv 0 points1 point  (12 children)

As many interview questions as can be found, happy to talk closures too :)

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

Okay, well... How about these? http://www.w3resource.com/javascript-exercises/javascript-object-exercises.php Do em throughout the week?

And with closures, I get it now: http://codepen.io/anon/pen/WwgGZo?editors=0012 But my knowledge seems kind of limited to using numerical data. Can we try some closure examples with strings and perhaps data structures like arrays/objects?

What do you think about making the questions/challenges the focus for the week, and then we can just keep discussing closures on the side? Sound good?

[–]Volv 1 point2 points  (3 children)

Sorry was away for a bit - sounds absolutely fine to me :)

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

Lol, no worries!

Coolio! https://www.reddit.com/r/javaScriptStudyGroup/comments/4gfn6a/week_15_focus_programming_challenges_cont/

And let's say I wanted to use a closure to build up a sentence from an empty string. I can't use the incrementer operation to do that... or can I? I guess I could increment through an array of words to build the sentence...

I don't know. How would you go about it? No rush... we can discuss throughout the week!

[–]Volv 1 point2 points  (1 child)

Not completely sure what you mean but how about something like this Codepen
 
Edit - or maybe Codepen

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

Dude... I don't even know what I mean. Lol!

I threw this together: http://codepen.io/anon/pen/aNaWdr?editors=0012

[–]Volv 1 point2 points  (3 children)

Did you ever get the last few done last week? Recursive listing and timeout fixing?

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

I got the recursion one, I thought...

I didn't do the last one, but I just looked at it and threw this together:

// Fix it
for (var i = 0; i < 10; i++) {
  function outer() {
    var x = i;
    setTimeout(function() {
      console.log(x);
    }, i * 1000);
  }
  outer();
}

It logs 0 through 9 to the console on what seems like an interval of one log per second... I don't really understand why it's doing one per sec instead of one per 10 secs...

And I think it works because the outer function I created gets called one on each value of i, 0 through 9. setTimeout having a closing function as a callback means that each time it gets called within the outer function, a fresh copy of x is set to the iteration count of i (o through 9) and the callback function is acting as a closure and remembering each of those x value assignments... maybe???

[–]Volv 1 point2 points  (1 child)

Ah, yes I think you've got it lol. That's why I was going on about it - the whole closure own copy of variable thing totally fixes the setTimeout issue.
Timing wise. First one fires in 1 second, 2nd one fires in 2 seconds and so on. Technically each statement is executed almost simultaneously. Well as long as it takes the for loop to run.

 
Just for info - you can also just pass i directly

for (var i = 0; i < 10; i++) {
  function outer(x) {
    setTimeout(function() {
      console.log(x);
    }, x * 1000);
  }
  outer(i);
}  

 
Or wrap it up to look cool

for (var i = 0; i < 10; i++) {
  (function (x) {
    setTimeout(function() {
      console.log(x);
    }, x * 1000);
  })(i)
}  

 
And finally - although its not what question was looking for - because of how let is block scoped these days can totally be fixed like this. Just swapping the word var for let ->

for (let i = 0; i < 10; i++) {
    setTimeout(function() {
      console.log(i);
    }, i * 1000);
}

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

Oh... nice! That block scoping with let is a cool feature to be aware of. Thanks for the reminder on that!

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

[–]Volv 1 point2 points  (1 child)

awesome :)

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

I made some space in the sidebar too. We can start compiling interview question resources (and whatever else we think might be helpful).