From 7f14c23f2d92c571a61ecbc83b01c742da697810 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Mon, 6 Aug 2018 14:05:44 +0000 Subject: [PATCH] Travis build: 196 --- docs/beginner.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/beginner.html b/docs/beginner.html index 1467b9e6f..6983a3e1a 100644 --- a/docs/beginner.html +++ b/docs/beginner.html @@ -56,7 +56,10 @@ document.getElementById('doc-drawer-checkbox').checked = false; } }, false); - }

logo 30 seconds of code

Curated collection of useful JavaScript snippets
that you can understand in 30 seconds or less.

Snippets for Beginners

The following section is aimed towards individuals who are at the start of their web developer journey. Each snippet in the next section is simple yet very educational for newcomers. This section is by no means a complete resource for learning modern JavaScript. However, it is enough to grasp some common concepts and use cases. We also strongly recommend checking out MDN web docs as a learning resource.


currentURL

Returns the current URL.

Use window.location.href to get current URL.

const currentURL = () => window.location.href;
+      }

logo 30 seconds of code

Curated collection of useful JavaScript snippets
that you can understand in 30 seconds or less.

Snippets for Beginners

The following section is aimed towards individuals who are at the start of their web developer journey. Each snippet in the next section is simple yet very educational for newcomers. This section is by no means a complete resource for learning modern JavaScript. However, it is enough to grasp some common concepts and use cases. We also strongly recommend checking out MDN web docs as a learning resource.


allEqual

Check if all elements are equal

Use Array.every() to check if all the elements of the array are the same as the first one.

const allEqual = arr => arr.every(val => val === arr[0]);
+
allEqual([1, 2, 3, 4, 5, 6]); // false
+allEqual([1, 1, 1, 1]); // true
+

currentURL

Returns the current URL.

Use window.location.href to get current URL.

const currentURL = () => window.location.href;
 
currentURL(); // 'https://google.com'
 

everyNth

Returns every nth element in an array.

Use Array.filter() to create a new array that contains every nth element of a given array.

const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
 
everyNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ]