From fd008df60a222c07e9e36b506911bf34fb3bb4c7 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Tue, 19 Dec 2017 23:33:05 +0530 Subject: [PATCH 01/25] Snippet to convert array to HTML list items --- snippets/arrayToHtmlList.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 snippets/arrayToHtmlList.md diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md new file mode 100644 index 000000000..a24b06b82 --- /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. + + +```js +const arrayToHtmlList = (arr, listID) =>arr.map(item =>document.querySelector("#"+listID).innerHTML+=`
  • ${item}
  • `); + +``` + From f9174c38fae061ccc47e9ffcb14b6b19d5eface3 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Tue, 19 Dec 2017 23:39:50 +0530 Subject: [PATCH 02/25] Fixed markdown typo --- snippets/arrayToHtmlList.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md index a24b06b82..ffa5b5aaa 100644 --- a/snippets/arrayToHtmlList.md +++ b/snippets/arrayToHtmlList.md @@ -1,6 +1,6 @@ ### arrayToHtmlList -Converts the given array elements into
  • tags and appends them to the list of the given id. +Converts the given array elements into 'li' tags and appends them to the list of the given id. ```js From 0537140cb63bafbb687c744904a3f25e9e39312e Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 00:23:56 +0530 Subject: [PATCH 03/25] Snippet to convert string to array of words --- snippets/stringToArrayOfWords.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 snippets/stringToArrayOfWords.md diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md new file mode 100644 index 000000000..5cc742c60 --- /dev/null +++ b/snippets/stringToArrayOfWords.md @@ -0,0 +1,14 @@ +### stringToArrayOfWords + +Converts a given string into an array of words + +First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(' ')` to conver string to array with the space a delimiter. + +```js +const stringToArray = str =>{ + [".", ",", "?", "!", "& ", "(", ")", "[", "]"].map(d => str = str.replace(d, "")); + return str.split(" "); +} + +// stringToArrayOfWords("I love javaScript!!") -> ["I", "love", "javaScript"] +``` \ No newline at end of file From 5316aed7929301e84260f83cf110e399519fedc6 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 00:28:34 +0530 Subject: [PATCH 04/25] Fixed typo and added another example --- snippets/stringToArrayOfWords.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index 5cc742c60..851f93397 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -2,7 +2,7 @@ Converts a given string into an array of words -First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(' ')` to conver string to array with the space a delimiter. +First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(' ')` to conver the string to an array with the space as a delimiter. ```js const stringToArray = str =>{ @@ -11,4 +11,5 @@ const stringToArray = str =>{ } // stringToArrayOfWords("I love javaScript!!") -> ["I", "love", "javaScript"] +// stringToArrayOfWords("python, javaScript & coffee") -> ["python", "javaScript", "coffee"] ``` \ No newline at end of file From a480757eef602070e8ea586874e4983fb6990f4a Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 00:30:10 +0530 Subject: [PATCH 05/25] Fixed function name --- snippets/stringToArrayOfWords.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index 851f93397..c54e2cec4 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -5,7 +5,7 @@ Converts a given string into an array of words First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(' ')` to conver the string to an array with the space as a delimiter. ```js -const stringToArray = str =>{ +const stringToArrayOfWords = str =>{ [".", ",", "?", "!", "& ", "(", ")", "[", "]"].map(d => str = str.replace(d, "")); return str.split(" "); } From 9c11215714253427f60df21ca0f01159dc21bb80 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 01:33:54 +0530 Subject: [PATCH 06/25] Snippet for checking armstrong number --- snippets/isArmstrongNumber.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/isArmstrongNumber.md diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md new file mode 100644 index 000000000..d9a96be1e --- /dev/null +++ b/snippets/isArmstrongNumber.md @@ -0,0 +1,17 @@ +### 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 =>{ + let total = 0, arr = (digits+"").split(""); + arr.map(d =>total += Math.pow(parseInt(d), arr.length)) + if(total === digits) return true; return false; +} + +// isArmstrongNumber(1634) -> true +// isArmstrongNumber(371) -> true +// isArmstrongNumber(56) -> false +``` \ No newline at end of file From daaec3c8ca534e3cf47785b628d8e09caf48f221 Mon Sep 17 00:00:00 2001 From: anglee Date: Tue, 19 Dec 2017 16:38:18 -0500 Subject: [PATCH 07/25] Add initialize2DArray --- snippets/initialize2DArray.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 snippets/initialize2DArray.md diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md new file mode 100644 index 000000000..45047b819 --- /dev/null +++ b/snippets/initialize2DArray.md @@ -0,0 +1,12 @@ +### initialize2DArray + +Initializes an 2D array of given width and height and value. + +Use `.map()` to generate h rows where each is a new array of size w initialize with value. + +```js +const initialize2DArray = (w, h, val = null) => + Array(h).fill().map(() => Array(w).fill(val)); +// initializeArrayWithRange(2, 2, 0) -> [[0,0], +// [0,0]] +``` From 34447403300bf56d1af01a18e8dfcd96dbba87a0 Mon Sep 17 00:00:00 2001 From: anglee Date: Tue, 19 Dec 2017 16:46:05 -0500 Subject: [PATCH 08/25] Add default value description to initialize2DArray --- snippets/initialize2DArray.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md index 45047b819..03e007620 100644 --- a/snippets/initialize2DArray.md +++ b/snippets/initialize2DArray.md @@ -2,7 +2,7 @@ Initializes an 2D array of given width and height and value. -Use `.map()` to generate h rows where each is a new array of size w initialize with value. +Use `.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) => From 645e51d22254f2d7d37aaa48138b60320469eb65 Mon Sep 17 00:00:00 2001 From: anglee Date: Tue, 19 Dec 2017 16:50:36 -0500 Subject: [PATCH 09/25] Minor text update --- snippets/initialize2DArray.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md index 03e007620..1a74440da 100644 --- a/snippets/initialize2DArray.md +++ b/snippets/initialize2DArray.md @@ -2,7 +2,7 @@ Initializes an 2D array of given width and height and value. -Use `.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. +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) => From 504a4c5c459f54c3bb9544db525ce67bdefc45fc Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 10:11:03 +0530 Subject: [PATCH 10/25] Added space after arrow --- snippets/isArmstrongNumber.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index d9a96be1e..4925f3dc8 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -5,13 +5,13 @@ 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 =>{ +const isArmstrongNumber = digits => { let total = 0, arr = (digits+"").split(""); - arr.map(d =>total += Math.pow(parseInt(d), arr.length)) + arr.map(d => total += Math.pow(parseInt(d), arr.length)) if(total === digits) return true; return false; } // isArmstrongNumber(1634) -> true // isArmstrongNumber(371) -> true // isArmstrongNumber(56) -> false -``` \ No newline at end of file +``` From 91d306877020dd07049d72ec2304b172d05ee5c9 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 10:11:58 +0530 Subject: [PATCH 11/25] Added space after arrow --- snippets/arrayToHtmlList.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md index ffa5b5aaa..7cc68081c 100644 --- a/snippets/arrayToHtmlList.md +++ b/snippets/arrayToHtmlList.md @@ -4,7 +4,7 @@ Converts the given array elements into 'li' tags and appends them to the list of ```js -const arrayToHtmlList = (arr, listID) =>arr.map(item =>document.querySelector("#"+listID).innerHTML+=`
  • ${item}
  • `); +const arrayToHtmlList = (arr, listID) => arr.map(item => document.querySelector("#"+listID).innerHTML+=`
  • ${item}
  • `); ``` From 05d52fe35a9d415949d862d3490cb04214c5e654 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 10:28:54 +0530 Subject: [PATCH 12/25] updated function --- snippets/stringToArrayOfWords.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index c54e2cec4..d0cea5793 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -5,9 +5,9 @@ Converts a given string into an array of words First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(' ')` to conver the string to an array with the space as a delimiter. ```js -const stringToArrayOfWords = str =>{ - [".", ",", "?", "!", "& ", "(", ")", "[", "]"].map(d => str = str.replace(d, "")); - return str.split(" "); +const stringToArrayOfWords = str => { + [".", ",", "?", "!", "& ", "(", ")", "[", "]"].map(d => str = str.split(d).join("")); + return str.split(/[\W_]+/); } // stringToArrayOfWords("I love javaScript!!") -> ["I", "love", "javaScript"] From 41041bb54d45da82b2179caef1a25ade7a8c48e0 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 10:33:07 +0530 Subject: [PATCH 13/25] updated discription --- snippets/stringToArrayOfWords.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index d0cea5793..2749a6869 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -2,7 +2,7 @@ Converts a given string into an array of words -First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(' ')` to conver the string to an array with the space as a delimiter. +First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(/[\W_]+/)` to convert the string to an array with the use of regex. ```js const stringToArrayOfWords = str => { From f1e28ed4343bb9655717d145b41492c55c5a6673 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 12:08:18 +0530 Subject: [PATCH 14/25] Updated function --- snippets/isArmstrongNumber.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index 4925f3dc8..d934dd715 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -5,10 +5,9 @@ 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 => { - let total = 0, arr = (digits+"").split(""); - arr.map(d => total += Math.pow(parseInt(d), arr.length)) - if(total === digits) return true; return false; +const isArmstrongNumber = num => { + let arr = (num+"").split(""); + return arr.reduce((a, d) => parseInt(a) + Math.pow(parseInt( d ), arr.length), 0) == num ? true : false } // isArmstrongNumber(1634) -> true From 4280957a102c0196041234786c2cd97189bd4761 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 12:26:10 +0530 Subject: [PATCH 15/25] Updated function with regex --- snippets/stringToArrayOfWords.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index 2749a6869..f0c5f149b 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -2,13 +2,10 @@ Converts a given string into an array of words -First create an array of dirt that you want to remove from the string. Then replace each dirt with an empty string. Use `String.split(/[\W_]+/)` to convert the string to an array with the use of regex. +Use `String.split(/[\W_]+/)` to convert the string to an array with the use of regex. ```js -const stringToArrayOfWords = str => { - [".", ",", "?", "!", "& ", "(", ")", "[", "]"].map(d => str = str.split(d).join("")); - return str.split(/[\W_]+/); -} +const stringToArrayOfWords = (str, pattern = /[\W_]+/) => str.split(pattern).filter(Boolean) // stringToArrayOfWords("I love javaScript!!") -> ["I", "love", "javaScript"] // stringToArrayOfWords("python, javaScript & coffee") -> ["python", "javaScript", "coffee"] From 5c4041d3941283ae50987c6c1a1d5a09bc4d1d6a Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 12:30:56 +0530 Subject: [PATCH 16/25] Updated function with help from @skatcat31 --- snippets/isArmstrongNumber.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index d934dd715..2b9f2970a 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -5,10 +5,7 @@ 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 = num => { - let arr = (num+"").split(""); - return arr.reduce((a, d) => parseInt(a) + Math.pow(parseInt( d ), arr.length), 0) == num ? true : false -} +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 From 251edb535b538532be3793b485bf48f307c450b2 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 12:34:03 +0530 Subject: [PATCH 17/25] updated description --- snippets/stringToArrayOfWords.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index f0c5f149b..4a7aa7c8a 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -2,11 +2,11 @@ Converts a given string into an array of words -Use `String.split(/[\W_]+/)` to convert the string to an array with the use of regex. +Use `String.split` to convert the string to an array. ```js const stringToArrayOfWords = (str, pattern = /[\W_]+/) => str.split(pattern).filter(Boolean) // stringToArrayOfWords("I love javaScript!!") -> ["I", "love", "javaScript"] // stringToArrayOfWords("python, javaScript & coffee") -> ["python", "javaScript", "coffee"] -``` \ No newline at end of file +``` From 16c40debe09de3a2fae581a57f819c848db9490d Mon Sep 17 00:00:00 2001 From: David Wu Date: Wed, 20 Dec 2017 08:15:23 +0100 Subject: [PATCH 18/25] Update PR template --- .github/PULL_REQUEST_TEMPLATE.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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. From 5ef9c25163d4c1225f82cf3e58dceb9e2c331b40 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 12:54:08 +0530 Subject: [PATCH 19/25] Updated description --- snippets/stringToArrayOfWords.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index 4a7aa7c8a..01bd6eb8b 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -2,7 +2,7 @@ Converts a given string into an array of words -Use `String.split` to convert the string to an array. +Use String.split with a supplied pattern(defaults to non alpha as a regex) to convert to an Array of Strings and then filter to remove any empty strings. ```js const stringToArrayOfWords = (str, pattern = /[\W_]+/) => str.split(pattern).filter(Boolean) From 1fc0e8754044d6db6b5071ddaa5ff325f90e12fe Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Wed, 20 Dec 2017 13:06:12 +0530 Subject: [PATCH 20/25] Updated function for not splitting hyphenated words --- snippets/stringToArrayOfWords.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index 01bd6eb8b..885216a58 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -5,7 +5,7 @@ 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 and then filter to remove any empty strings. ```js -const stringToArrayOfWords = (str, pattern = /[\W_]+/) => str.split(pattern).filter(Boolean) +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"] From 91b09861ba7ed4355e3322c730c03fd9a65b095a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BA=8C?= <1206180097@qq.com> Date: Wed, 20 Dec 2017 15:40:58 +0800 Subject: [PATCH 21/25] Update truthCheckCollection.md --- snippets/truthCheckCollection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ``` From c6d1e63bfd1089aca3d837648c76106beccd2fc8 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 20 Dec 2017 11:08:42 +0200 Subject: [PATCH 22/25] Update arrayToHtmlList.md --- snippets/arrayToHtmlList.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md index 7cc68081c..1dab3c778 100644 --- a/snippets/arrayToHtmlList.md +++ b/snippets/arrayToHtmlList.md @@ -1,10 +1,10 @@ ### arrayToHtmlList -Converts the given array elements into 'li' tags and appends them to the list of the given id. +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') ``` - From 3c66ced74ef2a3fcae9dadc95858cb029933fe3c Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 20 Dec 2017 11:10:54 +0200 Subject: [PATCH 23/25] Update isArmstrongNumber.md --- snippets/isArmstrongNumber.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index 2b9f2970a..be8857784 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -5,8 +5,8 @@ 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( '' ) ) - +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 From 972be8f37a449c6bcf24bf3d35e6c4263dc68641 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 20 Dec 2017 11:13:05 +0200 Subject: [PATCH 24/25] Update initialize2DArray.md --- snippets/initialize2DArray.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md index 1a74440da..cc8b8817b 100644 --- a/snippets/initialize2DArray.md +++ b/snippets/initialize2DArray.md @@ -2,11 +2,9 @@ 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. +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]] +const initialize2DArray = (w, h, val = null) => Array(h).fill().map(() => Array(w).fill(val)); +// initializeArrayWithRange(2, 2, 0) -> [[0,0], [0,0]] ``` From 00c3ff7a72922b0efdce4ff955017f216e8d7db5 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 20 Dec 2017 11:19:07 +0200 Subject: [PATCH 25/25] Update stringToArrayOfWords.md --- snippets/stringToArrayOfWords.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/stringToArrayOfWords.md b/snippets/stringToArrayOfWords.md index 885216a58..0630fe08a 100644 --- a/snippets/stringToArrayOfWords.md +++ b/snippets/stringToArrayOfWords.md @@ -1,12 +1,12 @@ ### stringToArrayOfWords -Converts a given string into an array of words +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 and then filter to remove any empty strings. +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) - +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"] ```