Skip to content

Instantly share code, notes, and snippets.

@PenneyGadget
Last active March 24, 2016 15:11
Show Gist options
  • Save PenneyGadget/b351951905629a3d2f77 to your computer and use it in GitHub Desktop.
Save PenneyGadget/b351951905629a3d2f77 to your computer and use it in GitHub Desktop.
Array.prototype review

I understand that functions in JavaScript can take any number of arguments.

  • Indeed! I like it!

I can describe the similarity between blocks in Ruby and anonymous functions in JavaScript.

  • Yes. In Ruby we pass a block in which we name an anonymous variable to be a placeholder for whatever we are iterating through. The anonymous function is the same - we can pass in the arguments we want to use in our iteration and name them as we see fit. Or we can pass in a function that we have already created.

Where are the methods available to all arrays (e.g. forEach, map, etc.) defined?

  • Array.prototype

I can explain the difference between using a for loop and the forEach method.

  • With a for loop we set the criteria in regards to the start and stop point, as well as how we increment through whatever we are iterating over. With .forEach we send a collection into the anonymous function and it will iterate through each element just like Ruby does.

  • The for loop is faster but not as human-friendly to read.

  • With .forEach our element argument is scoped only to our callback function, whereas the variable we declare in the setup for a for loop is available outside the loop body.

I can explain the difference between forEach and map.

  • Just like in Ruby, .forEach returns undefined after it's finished - .map returns a transformed array.

Can you explain the process of taking a plain JavaScript objects, transforming them into DOM nodes, and appending them to the page.

  • Sort of? I found this part the most confusing though. So with document.createElement we can assign an element to a variable/object and then add we can set the properties of that element. So.. var newThing = document.createElement('img'); --> we have our new element newThing.alt = thingWeAreIteratingOver.theThingThatWillBecomeTheAlt; --> here we add a property to our element

  • appendChild (without JQuery) or append (JQuery) can then be used to add our element to the page where we want it. I understand this when I say it in a pseudocode manner like this, but don't feel like I'd know how to implement it properly. I'm having a hard time with JQuery/DOM stuff in general.

How comfortable are you using the forEach() method?

  • I feel pretty good about this - seems straight forward.

How comfortable are you using the map() method?

  • Great, it functions just like Ruby.

How comfortable are you using the filter() method?

  • Good in concept. I imagine I'll run into some issues when the logic gets more complicated. The indexOf stuff is a bit tricky.

How comfortable are you using the reduce() method?

  • Same as .filter, I understand it well in concept and with simple examples, but I can see how it will be pretty hairy with more complicated problems.

How comfortable are you using the sort() method?

  • Fine I think. I wish there had been tests for this method in the exercise.

How comfortable are you working with simple unit tests in Mocha in the browser?

  • Fine, though I wouldn't know how to write them/set them up yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment