Array
@@ -234,7 +233,7 @@ If the original array can't be split evenly, the final chunk will contain the recompact
Removes falsey values from an array.
Use Array.filter() to filter out falsey values (false, null, 0, "", undefined, and NaN).
const compact = (arr) => arr.filter(Boolean);
+const compact = arr => arr.filter(Boolean);
// compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ]
countOccurrences
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 === 0);
-// everyNth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ]
+const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
+// everyNth([1,2,3,4,5,6], 2) -> [ 2, 4, 6 ]
filterNonUnique
Filters out the non-unique values in an array.
@@ -869,12 +868,11 @@ Returnstrue if the number is even, false if the numbe
Checks if the provided integer is a prime number.
Returns false if the provided number has positive divisors other than 1 and itself or if the number itself is less than 2.
const isPrime = num => {
- for (var i = 2; i < num; i++) if (num % i == 0) return false;
+ for (var i = 2; i * i <= num; i++) if (num % i == 0) return false;
return num >= 2;
-}
+};
// isPrime(11) -> true
// isPrime(12) -> false
-// isPrime(1) -> false
lcm
Returns the least common multiple of two numbers.
@@ -1318,14 +1316,6 @@ If digit is found in teens pattern, use teens ordinal. ); // UUIDGenerator() -> '7982fcfe-5721-4632-bede-6000885be57d' -validateEmail
Returns true if the given string is a valid email, false otherwise.
Use a regular expression to check if the email is valid.
-Returns true if email is valid, false if not.
const validateEmail = str =>
- /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(str);
-// validateEmail(mymail@gmail.com) -> true
-
validateNumber
Returns true if the given value is a number, false otherwise.
Use !isNaN in combination with parseFloat() to check if the argument is a number.
diff --git a/snippets/compact.md b/snippets/compact.md
index c63796719..d09160afe 100644
--- a/snippets/compact.md
+++ b/snippets/compact.md
@@ -5,6 +5,6 @@ Removes falsey values from an array.
Use `Array.filter()` to filter out falsey values (`false`, `null`, `0`, `""`, `undefined`, and `NaN`).
```js
-const compact = (arr) => arr.filter(Boolean);
+const compact = arr => arr.filter(Boolean);
// compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ]
```
diff --git a/snippets/everyNth.md b/snippets/everyNth.md
index 0c79e3a1f..f326ebe2b 100644
--- a/snippets/everyNth.md
+++ b/snippets/everyNth.md
@@ -5,6 +5,6 @@ Returns every nth element in an array.
Use `Array.filter()` to create a new array that contains every nth element of a given array.
```js
-const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === 0);
-// everyNth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ]
+const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
+// everyNth([1,2,3,4,5,6], 2) -> [ 2, 4, 6 ]
```
diff --git a/snippets/isPrime.md b/snippets/isPrime.md
index cc1f69b14..0a2157e2f 100644
--- a/snippets/isPrime.md
+++ b/snippets/isPrime.md
@@ -6,10 +6,9 @@ Returns `false` if the provided number has positive divisors other than 1 and it
```js
const isPrime = num => {
- for (var i = 2; i < num; i++) if (num % i == 0) return false;
+ for (var i = 2; i * i <= num; i++) if (num % i == 0) return false;
return num >= 2;
-}
+};
// isPrime(11) -> true
// isPrime(12) -> false
-// isPrime(1) -> false
```
diff --git a/snippets/validateEmail.md b/snippets/validateEmail.md
deleted file mode 100644
index cb5588474..000000000
--- a/snippets/validateEmail.md
+++ /dev/null
@@ -1,12 +0,0 @@
-### validateEmail
-
-Returns `true` if the given string is a valid email, `false` otherwise.
-
-Use a regular expression to check if the email is valid.
-Returns `true` if email is valid, `false` if not.
-
-```js
-const validateEmail = str =>
- /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(str);
-// validateEmail(mymail@gmail.com) -> true
-```
diff --git a/static-parts/README-start.md b/static-parts/README-start.md
index c1dc07e51..05f368b4a 100644
--- a/static-parts/README-start.md
+++ b/static-parts/README-start.md
@@ -3,6 +3,7 @@
# 30 seconds of code [](https://gitter.im/30-seconds-of-code/Lobby) [](https://travis-ci.org/Chalarangelo/30-seconds-of-code)
> Curated collection of useful Javascript snippets that you can understand in 30 seconds or less.
+
- Use Ctrl + F or command + F to search for a snippet.
- Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
- Snippets are written in ES6, use the [Babel transpiler](https://babeljs.io/) to ensure backwards-compatibility.
diff --git a/tag_database b/tag_database
index 6e965bf45..78da7daaf 100644
--- a/tag_database
+++ b/tag_database
@@ -119,7 +119,6 @@ truncateString:string
truthCheckCollection:object
union:array
UUIDGenerator:utility
-validateEmail:utility
validateNumber:utility
without:array
words:string