diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 940c318b4..310dae48f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,13 +1,19 @@ - + ## Description **Resolves** #(issue number) +## 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. diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md new file mode 100644 index 000000000..1dab3c778 --- /dev/null +++ b/snippets/arrayToHtmlList.md @@ -0,0 +1,10 @@ +### arrayToHtmlList + +Converts the given array elements into '
  • ' 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+=`
  • ${item}
  • `); +// arrayToHtmlList(['item 1', 'item 2'],'myListID') +``` diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md new file mode 100644 index 000000000..cc8b8817b --- /dev/null +++ b/snippets/initialize2DArray.md @@ -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]] +``` diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md new file mode 100644 index 000000000..be8857784 --- /dev/null +++ b/snippets/isArmstrongNumber.md @@ -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 +``` diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md new file mode 100644 index 000000000..0630fe08a --- /dev/null +++ b/snippets/stringToArrayOfWords.md @@ -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"] +``` diff --git a/snippets/truthCheckCollection.md b/snippets/truthCheckCollection.md index 82a6d26cd..3c592d308 100644 --- a/snippets/truthCheckCollection.md +++ b/snippets/truthCheckCollection.md @@ -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 ```