Merge pull request #8 from Chalarangelo/master
This commit is contained in:
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,13 +1,19 @@
|
||||
<!--- Provide a general summary of your changes in the Title above -->
|
||||
|
||||
<!--- Add the prefix [FIX: #(issue number)] or [FEATURE] to the Title -->
|
||||
<!--- Add the prefix [FIX: #(issue number)], [FEATURE] or [ENHANCEMENT] to the Title -->
|
||||
|
||||
## Description
|
||||
<!--- Describe your changes in detail -->
|
||||
**Resolves** #(issue number) <!--- Delete if not a issue fix-->
|
||||
|
||||
## What does your PR belong to?
|
||||
- [ ] Website
|
||||
- [ ] Snippets
|
||||
- [ ] General / Things regarding the repository (like CI Integration)
|
||||
|
||||
## Types of changes
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] Enhancement (non-breaking improvement of a snippet)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
@ -16,5 +22,6 @@
|
||||
- [ ] My code follows the code style of this project.
|
||||
- [ ] My change requires a change to the documentation.
|
||||
- [ ] I have updated the documentation accordingly.
|
||||
- [ ] I have checked that the changes are working properly
|
||||
- [ ] I have checked that there isn't any PR doing the same
|
||||
- [ ] I have read the **CONTRIBUTING** document.
|
||||
|
||||
10
snippets/arrayToHtmlList.md
Normal file
10
snippets/arrayToHtmlList.md
Normal file
@ -0,0 +1,10 @@
|
||||
### arrayToHtmlList
|
||||
|
||||
Converts the given array elements into '<li>' tags and appends them to the list of the given id.
|
||||
|
||||
Use `Array.map()` and `document.querySelector()` to create a list of html tags.
|
||||
|
||||
```js
|
||||
const arrayToHtmlList = (arr, listID) => arr.map(item => document.querySelector("#"+listID).innerHTML+=`<li>${item}</li>`);
|
||||
// arrayToHtmlList(['item 1', 'item 2'],'myListID')
|
||||
```
|
||||
10
snippets/initialize2DArray.md
Normal file
10
snippets/initialize2DArray.md
Normal file
@ -0,0 +1,10 @@
|
||||
### initialize2DArray
|
||||
|
||||
Initializes an 2D array of given width and height and value.
|
||||
|
||||
Use `Array.map()` to generate h rows where each is a new array of size w initialize with value. If value is not provided, default to `null`.
|
||||
|
||||
```js
|
||||
const initialize2DArray = (w, h, val = null) => Array(h).fill().map(() => Array(w).fill(val));
|
||||
// initializeArrayWithRange(2, 2, 0) -> [[0,0], [0,0]]
|
||||
```
|
||||
13
snippets/isArmstrongNumber.md
Normal file
13
snippets/isArmstrongNumber.md
Normal file
@ -0,0 +1,13 @@
|
||||
### isArmstrongNumber
|
||||
|
||||
Checks if the given number is an armstrong number or not.
|
||||
|
||||
Convert the given number into array of digits. Use `Math.pow()` to get the appropriate power for each digit and sum them up. If the sum is equal to the number itself, return `true` otherwise `false`.
|
||||
|
||||
```js
|
||||
const isArmstrongNumber = digits =>
|
||||
( arr => arr.reduce( ( a, d ) => a + Math.pow( parseInt( d ), arr.length ), 0 ) == digits ? true : false )( ( digits+'' ).split( '' ) );
|
||||
// isArmstrongNumber(1634) -> true
|
||||
// isArmstrongNumber(371) -> true
|
||||
// isArmstrongNumber(56) -> false
|
||||
```
|
||||
12
snippets/stringToArrayOfWords.md
Normal file
12
snippets/stringToArrayOfWords.md
Normal file
@ -0,0 +1,12 @@
|
||||
### stringToArrayOfWords
|
||||
|
||||
Converts a given string into an array of words.
|
||||
|
||||
Use `String.split()` with a supplied pattern (defaults to non alpha as a regex) to convert to an array of strings. Use `Array.filter()` to remove any empty strings.
|
||||
Omit the second argument to use the default regex.
|
||||
|
||||
```js
|
||||
const stringToArrayOfWords = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
||||
// stringToArrayOfWords("I love javaScript!!") -> ["I", "love", "javaScript"]
|
||||
// stringToArrayOfWords("python, javaScript & coffee") -> ["python", "javaScript", "coffee"]
|
||||
```
|
||||
@ -5,6 +5,6 @@ Checks if the predicate (second argument) is truthy on all elements of a collect
|
||||
Use `Array.every()` to check if each passed object has the specified property and if it returns a truthy value.
|
||||
|
||||
```js
|
||||
truthCheckCollection = (collection, pre) => (collection.every(obj => obj[pre]));
|
||||
const truthCheckCollection = (collection, pre) => (collection.every(obj => obj[pre]));
|
||||
// truthCheckCollection([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}], "sex") -> true
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user