Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save martensonbj/ea3d968b0e476301fe37 to your computer and use it in GitHub Desktop.
Save martensonbj/ea3d968b0e476301fe37 to your computer and use it in GitHub Desktop.
Checks for Understanding - JS Array Prototypes

Array Prototype Methods

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

  • I also understand that you can ask for the arguments to be printed to the console if you're confused with what is being considered an argument. console.log(arguments)- JS MAGIC!

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

  • Ruby functions take blocks like so: array.each do {|thing| thing.to_s } which then iterates over said thing and makes it a string.
  • JS functions take anonymous functions that implicitly call an object, using the "any number of arguments but one of those arguments will be an individual element" idea: ```array.forEach(function(thing){ thing.toUpperCase });

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

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

  • for loops put you at risk for weird things happening because i can be accessed outside of the block and if you aren't aware of what i is things could get crazy. forEach() loops scope the variables inside the function, establishing a safer workzone.

I can explain the difference between forEach and map.

  • .forEach() is similar to .each in Ruby in that it iterates over a collection and passes each element through an anonymous function, without transforming the orginal contents of the array. And, like in ruby, the function will return undefined when finished.
  • .map() is similar to .map in Ruby in that it iterates over a collection and returns a new array of elements, but transforms that collection into something new. The function will return the transformed array (when explicitly called).

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

  • With JS, you can iterate over a colleciton of elements and turn those elements into DOM nodes with the following process:
// create an HTML image element
  var newDomObject = document.createElement('img'); //or other HTML object 
// set properties of said element necessary for proper HTML syntax
  newDomObject.alt = thing.caption
  newDomObject.src = thing.image_url
// return HTML object
  return newDomObject
}.forEach(function(newDomObject){
//get the HTML element you want to add each newly created DOM node to
document.getElementById('IdOfHTMLElement').appendChild(newDomObject)
})```

How comfortable are you using the `forEach()` method?
- Pretty comfortable. Will forget it returns undefined just like I forgot Ruby's `each` returns nill

How comfortable are you using the `map()` method?
- Getting better. I'm starting to get more comfortable with how JS syntax looks and feels. 

How comfortable are you using the `filter()` method?
- Semi. Haven't used it much, but probably will for an extension on this project! Woop woop. 

How comfortable are you using the `reduce()` method?
- Hardly. For some reason someone (probably Horace) scared me about Reduce in Mod1 and I still haven't gotten rid of the negative connotations with it. Not sure why. 

How comfortable are you using the `sort()` method?
- This tutorial/video actually really made sense - and made the rocket ship from Ruby make way more sense too. 

How comfortable are you working with simple unit tests in Mocha in the browser?
- Not at all. I can understand what they're asking and I know how to delete the part that says "skip" but in reality having to write them from scratch on my own is going to be a disaster. 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment