#JavaScript30 – Day 04

Day 4 consisted of what Wes called JavaScript cardio – exercises in JS.

The focus on this video was arrays and 4 array functions:

.filter()

filter() will create a new array with all of the elements from another array that pass a test from a function.

.map()

The map() method takes in an array, performs a functions for each element in the array, then returns a new array of the same length.

.sort()

Using sort() will sort the elements of an array inside of the array. It will take 2 items at a time, determines if one is a higher value, then will place them at a higher or lower index respectively.

.reduce()

reduce() performs a function against each value in the array and an”accumulator” (like a running total), then reduces it to a single value.

 

They’re all functions that I have seen in solutions for JS exercises in places like Free Code Camp  and HackerRank, but never really understood how or why they are used. And, even though I can tell you what they do, I could still use some work getting more comfortable actually working with these methods. Now that I’ve done this exercise once while just following along, I plan on going back to exercises like these to attempt to solve them on my own. I also have ideas on how to solve at least one of the FreeCodeCamp algorithm scripting challenges I’ve been stuck on.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s