From 343bed93d3c709ce4bbde40113c2209e7cf6a47d Mon Sep 17 00:00:00 2001 From: amaddatu <> Date: Tue, 19 Jan 2021 18:23:28 -0500 Subject: [PATCH 1/2] Add stylesheet and fix typos and remove breaks --- assets/css/style.css | 33 ++++++++++++++++++++ index.html | 71 ++++++++++---------------------------------- 2 files changed, 49 insertions(+), 55 deletions(-) create mode 100644 assets/css/style.css diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 0000000..5f04627 --- /dev/null +++ b/assets/css/style.css @@ -0,0 +1,33 @@ +body { + margin: 0; + padding: 0; + font-family: Trebuchet MS; + display:flex; + flex-direction: column; + text-align: center; + background-color:#F2C166; + } + header, main, footer { + max-width: 1200px; + margin-left: auto; + margin-right: auto; + } + + h2 { + margin-left: auto; + margin-right: auto; + display: block; + max-width: 900px; + } + + h1, h2, h3, p { + color:#A60321; + } + + hr { + background-color:#A60321; + border: 0px; + height: 2.3px; + border-radius: 3px; + } + diff --git a/index.html b/index.html index 73db75d..6b4ce2f 100644 --- a/index.html +++ b/index.html @@ -4,42 +4,7 @@ Array Methods in JavaScript - +
@@ -48,32 +13,30 @@

What's the difference between map() and forEach()

If this is the first you are reading about these array methods. Let me give you a quick defintion of each of these methods and their purpose, before we dig a little deeper.

-
-
-

From The Mozilla Documentation, The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

-
-

From The Mozilla Documentation, The forEach() method executes a provided function once for each array element.

-
-
+ +

From The Mozilla Documentation, The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

+ +

From The Mozilla Documentation, The forEach() method executes a provided function once for each array element.

+

These definitions aren't great, simply put both these methods execute a call back function on each item in an array.

-
+

So, to understand the mechanics of these array methods we start first have to start with an array.

-
+

Now let's run each method on the array as followed...

-
+

Here's the map() method in action

-
+

Here's the forEach() method in action

Upon basic execution, both map() and forEach() return the same results and perform the same task.

-
+

Now it's time to go a little deeper...

-
+

So both both map() and forEach() provide three parameter variables in their call back function. I've named them item, index, array, but feel free to give them any name you (pro tip: refer to the MDN documentation for the proper naming convetions).

We've seen the item variable in action, now lets look at the index variable for these methods.

@@ -83,7 +46,7 @@

Here's the map() method in action returing it

And, here's the forEach() method in action returing it's index variable parameter

-
+

Same results...

Here's the map() method in action returing it's array variable parameter

@@ -91,10 +54,8 @@

Here's the map() method in action returing it

And, here's the forEach() method in action returing it's array variable parameter

Again, they return the same results...

-

Say, what's going on here? Why do we have two methods that so far do exactly the same thing?

-

Let's keep digging...

-
+

At this point, I'll say about these methods its not what they do that makes them different, but its how they are used that seperates them.

Let's explore

@@ -116,9 +77,9 @@

Here's another example. Lets see what happens when we set each of these meth

The reason forEach() returns undefined when set to a variable is because it executes a call back once on each item to an array.

So there is a conflict of usage when setting that callback execution to a variable. The browser doesn't know how to interpret one variable set to the results of a callback on each item.

Unlike forEach(), the map() method creates a new array on execution, so setting it to a variable will simply return the items recreated as a new array.

-

As of right now, that's all I have to say about these array methods by making a comparission I hope I've demostrated how they function and there purpose on a deeper level.

+

As of right now, that's all I have to say about these array methods by making a comparision I hope I've demonstrated how they function and their purpose on a deeper level.

If you have any question feel free to make a pull request on this repo and commit your questions.

-

This site is also suplemental material for an article I wrote on the subject called The power of the map method +

This site is also supplemental material for an article I wrote on the subject called The power of the map method.


From 3bf09fabd3cba395b878bcf146aa5ec98d365144 Mon Sep 17 00:00:00 2001 From: amaddatu <> Date: Tue, 19 Jan 2021 18:31:39 -0500 Subject: [PATCH 2/2] Add style changes --- assets/css/style.css | 12 ++++++++---- index.html | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index 5f04627..c961424 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -1,11 +1,12 @@ body { - margin: 0; + margin: 0 auto; + max-width: 1000px; padding: 0; font-family: Trebuchet MS; display:flex; flex-direction: column; text-align: center; - background-color:#F2C166; + background-color:#ECDEFF; } header, main, footer { max-width: 1200px; @@ -18,14 +19,17 @@ body { margin-right: auto; display: block; max-width: 900px; + padding: 3% 10%; + font-size: 17px; + text-align: left; } h1, h2, h3, p { - color:#A60321; + color:#9D54FD; } hr { - background-color:#A60321; + background-color:#9D54FD; border: 0px; height: 2.3px; border-radius: 3px; diff --git a/index.html b/index.html index 6b4ce2f..149c899 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@

What's the difference between map() and forEach()


-

If this is the first you are reading about these array methods. Let me give you a quick defintion of each of these methods and their purpose, before we dig a little deeper.

+

If this is the first you are reading about these array methods. Let me give you a quick definition of each of these methods and their purpose, before we dig a little deeper.

From The Mozilla Documentation, The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.