From cab9b9fefe9f579887222203b6ba62b875069095 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 22 Dec 2017 18:13:22 +0200 Subject: [PATCH 01/48] Add toSnakeCase --- snippets/toSnakeCase.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 snippets/toSnakeCase.md diff --git a/snippets/toSnakeCase.md b/snippets/toSnakeCase.md new file mode 100644 index 000000000..0ea69bcaf --- /dev/null +++ b/snippets/toSnakeCase.md @@ -0,0 +1,14 @@ +### toSnakeCase + +Converts a string to snakecase. + +Use `replace()` to add underscores before capital letters, convert `toLowerCase()`, then `replace()` hyphens and spaces with underscores. + +```js +const toSnakeCase = str => + str.replace(/[A-Z]/g, (match, p1, p2, offset) => '_' + match).toLowerCase().replace(/[\s-]+/g,'_'); +// toSnakeCase("camelCase") -> 'camel_case' +// toSnakeCase("some text") -> 'some_text' +// toSnakeCase("some-javascript-property") -> 'some_javascript_property' +// toSnakeCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some_mixed_string_with_spaces_underscores_and_hyphens' +``` From 485ded30387fb3ce8330f471252fd3ba546c106e Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 22 Dec 2017 18:15:55 +0200 Subject: [PATCH 02/48] Update tag_database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index deb4c8902..e1c6987d5 100644 --- a/tag_database +++ b/tag_database @@ -117,6 +117,7 @@ toCamelCase:string toDecimalMark:utility toEnglishDate:date toOrdinalSuffix:utility +toSnakeCase:string truncateString:string truthCheckCollection:object union:array From 9a23fc7420e2ec5af7a8623a1932292700fcbb22 Mon Sep 17 00:00:00 2001 From: Elder Henrique Souza Date: Fri, 22 Dec 2017 15:55:58 -0200 Subject: [PATCH 03/48] fixed issue described in pull request checks if the uppercase charcater is preceded by another character --- snippets/toSnakeCase.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/toSnakeCase.md b/snippets/toSnakeCase.md index 0ea69bcaf..6a82a5ba2 100644 --- a/snippets/toSnakeCase.md +++ b/snippets/toSnakeCase.md @@ -6,7 +6,7 @@ Use `replace()` to add underscores before capital letters, convert `toLowerCase( ```js const toSnakeCase = str => - str.replace(/[A-Z]/g, (match, p1, p2, offset) => '_' + match).toLowerCase().replace(/[\s-]+/g,'_'); + str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-]/g, '_').toLowerCase(); // toSnakeCase("camelCase") -> 'camel_case' // toSnakeCase("some text") -> 'some_text' // toSnakeCase("some-javascript-property") -> 'some_javascript_property' From 131be0e182c26931e633279e9e1c81449c9ac91b Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 23 Dec 2017 11:58:41 +0200 Subject: [PATCH 04/48] Fixed multiple spaces/hyphens/underscores --- snippets/toSnakeCase.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/toSnakeCase.md b/snippets/toSnakeCase.md index 6a82a5ba2..957fd3a78 100644 --- a/snippets/toSnakeCase.md +++ b/snippets/toSnakeCase.md @@ -6,7 +6,7 @@ Use `replace()` to add underscores before capital letters, convert `toLowerCase( ```js const toSnakeCase = str => - str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-]/g, '_').toLowerCase(); + str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-_]+/g, '_').toLowerCase(); // toSnakeCase("camelCase") -> 'camel_case' // toSnakeCase("some text") -> 'some_text' // toSnakeCase("some-javascript-property") -> 'some_javascript_property' From c816ce85ce88ab10b1a7833dd712b81557d6d20d Mon Sep 17 00:00:00 2001 From: David Narbutovich Date: Sat, 23 Dec 2017 14:00:04 +0300 Subject: [PATCH 05/48] =?UTF-8?q?Bad=20example=F0=9F=91=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The slice function can take the negative negative value of the second agrimement --- snippets/dropRight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/dropRight.md b/snippets/dropRight.md index d1a56d764..985df7ac3 100644 --- a/snippets/dropRight.md +++ b/snippets/dropRight.md @@ -5,7 +5,7 @@ Returns a new array with `n` elements removed from the right Check if `n` is shorter than the given array and use `Array.slice()` to slice it accordingly or return an empty array. ```js -const dropRight = (arr, n = 1) => n < arr.length ? arr.slice(0, arr.length - n) : [] +const dropRight = (arr, n = 1) => arr.slice(0, -n) //dropRight([1,2,3]) -> [1,2] //dropRight([1,2,3], 2) -> [1] //dropRight([1,2,3], 42) -> [] From 887f0e6bd4322785c580224b482f7d994a6d5361 Mon Sep 17 00:00:00 2001 From: Rohit Tanwar Date: Sat, 23 Dec 2017 18:45:16 +0530 Subject: [PATCH 06/48] add toKebabCase --- snippets/repeatString.md | 0 snippets/toKebabCase.md | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 snippets/repeatString.md create mode 100644 snippets/toKebabCase.md diff --git a/snippets/repeatString.md b/snippets/repeatString.md new file mode 100644 index 000000000..e69de29bb diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md new file mode 100644 index 000000000..2eaee9f2c --- /dev/null +++ b/snippets/toKebabCase.md @@ -0,0 +1,17 @@ +### toKebabCase + +Converts a string to snakecase. +Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` and undesrsocres and spaces with hyphens. +Also check if a string starts with hyphen and if yes remove it. + +```js +const toKebabCase = str => { + str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-'); + return str.startsWith('-') ? str.slice(1,str.length) : str; +} +// toKebabCase("camelCase") -> 'camel-case' +// toKebabCase("some text") -> 'some-text' +// toKebabCase("some-javascript-property") -> 'some-javascript-property' +// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' +// toKebabCase("AllThe-small Things") -> "all-the-small-things" +``` From 7bce20a45726b9df848280e4504c57707c911147 Mon Sep 17 00:00:00 2001 From: Rohit Tanwar Date: Sat, 23 Dec 2017 18:53:41 +0530 Subject: [PATCH 07/48] add repeatString --- snippets/repeatString.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/snippets/repeatString.md b/snippets/repeatString.md index e69de29bb..fbccf52d2 100644 --- a/snippets/repeatString.md +++ b/snippets/repeatString.md @@ -0,0 +1,17 @@ +### toKebabCase + +Repeats a string n times using String.repeat() + +If no string is provided the default is `""` and the default number of times is 1 + +```js +const repeatString = (str="",num=1) => { + return num >= 0 ? str.repeat(num) : str; +} +// toRepeatString("abc",3) -> 'abcabcabc' +// toRepeatString("abc",0) -> '' +// toRepeatString("abc") -> 'abc' +// toRepeatString("abc",-1) -> 'abc' +// toRepeatString() -> '' +// toRepeatString(undefined,3) -> '' +``` From 339fab74d5cb3243598b5a664d9670f0ba6970fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Sat, 23 Dec 2017 15:19:41 +0100 Subject: [PATCH 08/48] add buttons and eventListeners --- docs/bundle.js | 10 ++++++++++ docs/index.html | 2 ++ static-parts/index-end.html | 1 + static-parts/index-start.html | 1 + 4 files changed, 14 insertions(+) create mode 100644 docs/bundle.js diff --git a/docs/bundle.js b/docs/bundle.js new file mode 100644 index 000000000..eb3d70564 --- /dev/null +++ b/docs/bundle.js @@ -0,0 +1,10 @@ +var s = document.querySelectorAll("pre"); +s.forEach(element => { + var button = document.createElement("button"); + button.innerHTML = "Copy to clipboard"; + element.parentElement.appendChild(button); + + button.addEventListener ("click", function() { + console.log(element.textContent); + }); +}); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index ee07a9add..ecb78bb7a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -14,6 +14,7 @@ + + diff --git a/static-parts/index-end.html b/static-parts/index-end.html index 2dd2aae7e..1b89d551a 100644 --- a/static-parts/index-end.html +++ b/static-parts/index-end.html @@ -5,5 +5,6 @@ + diff --git a/static-parts/index-start.html b/static-parts/index-start.html index f6c71b064..d1e09b45c 100644 --- a/static-parts/index-start.html +++ b/static-parts/index-start.html @@ -14,6 +14,7 @@ + From 4281d0b8b55b22cff4e49426c1c5917e9bc8570e Mon Sep 17 00:00:00 2001 From: David Wu Date: Sat, 23 Dec 2017 16:02:20 +0100 Subject: [PATCH 12/48] Update repeatString.md --- snippets/repeatString.md | 1 - 1 file changed, 1 deletion(-) diff --git a/snippets/repeatString.md b/snippets/repeatString.md index 619fe767b..888965713 100644 --- a/snippets/repeatString.md +++ b/snippets/repeatString.md @@ -9,6 +9,5 @@ const repeatString = (str="",num=2) => { return num >= 0 ? str.repeat(num) : str; } // repeatString("abc",3) -> 'abcabcabc' -// repeatString("abc",0) -> '' // repeatString("abc") -> 'abcabc' ``` From 80faa076405377bac060548d07b6992dfcd8b061 Mon Sep 17 00:00:00 2001 From: David Wu Date: Sat, 23 Dec 2017 16:10:56 +0100 Subject: [PATCH 13/48] Update toKebabCase.md --- snippets/toKebabCase.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md index 2eaee9f2c..7d8fe09dd 100644 --- a/snippets/toKebabCase.md +++ b/snippets/toKebabCase.md @@ -1,8 +1,8 @@ ### toKebabCase -Converts a string to snakecase. -Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` and undesrsocres and spaces with hyphens. -Also check if a string starts with hyphen and if yes remove it. +Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). +Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes. ```js const toKebabCase = str => { @@ -11,7 +11,6 @@ const toKebabCase = str => { } // toKebabCase("camelCase") -> 'camel-case' // toKebabCase("some text") -> 'some-text' -// toKebabCase("some-javascript-property") -> 'some-javascript-property' // toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' // toKebabCase("AllThe-small Things") -> "all-the-small-things" ``` From 060c012a5281fe9b9dc3b9c306d459617548043e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Sat, 23 Dec 2017 16:11:17 +0100 Subject: [PATCH 14/48] build webber --- docs/index.html | 42 ++++++++++++++++++++++++++--------- static-parts/index-start.html | 8 +++---- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/docs/index.html b/docs/index.html index ecb78bb7a..a10547ab1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -22,6 +22,26 @@ var remove = false, childs = Array.from(node.parentElement.parentElement.children), toRemove = childs[0]; Array.from(node.parentElement.parentElement.children).forEach(x => x.tagName == 'H3' ? (toRemove.style.display = (remove ? 'none' : ''), toRemove = x, remove = true) : (x.style.display == '' ? remove = false : remove=remove)); } + + const snippets = document.querySelectorAll("pre"); + snippets.forEach(element => { + const button = document.createElement("button"); + button.innerHTML = "Copy to clipboard"; + element.parentElement.appendChild(button); + + button.addEventListener ("click", function() { + //The following regex removes all the comments from the snippet + const text = element.textContent.replace(/\/\*(.|[\r\n])*?\*\//g, '').replace(/\/\/.*/gm, ''); + // Apparently you can't copy a variable to clipboard so you need to create text input element, + // give it a value, copy it and then remove it from DOM. + const textArea = document.createElement("textarea"); + textArea.value = text; + document.body.appendChild(textArea); + textArea.select(); + document.execCommand("Copy"); + document.body.removeChild(textArea); + }); +}); @@ -273,7 +293,7 @@ arrayMax([1,2,4]) // -> 4

Use Array.reduce() and the lcm formula (uses recursion) to calculate the lowest common multiple of an array of numbers.

const arrayLcm = arr =>{
   const gcd = (x, y) => !y ? x : gcd(y, x % y);
-  const lcm = (x, y) => (x*y)/gcd(x, y); 
+  const lcm = (x, y) => (x*y)/gcd(x, y);
   return arr.reduce((a,b) => lcm(a,b));
 }
 // arrayLcm([1,2,3,4,5]) -> 60
@@ -417,7 +437,7 @@ Use Array.reduce() to create an object, where the keys are produced
 

Initializes an array containing the numbers in the specified range where start and end are inclusive.

Use Array((end + 1) - start) to create an array of the desired length, Array.map() to fill with the desired values in a range. You can omit start to use a default value of 0.

-
const initializeArrayWithRange = (end, start = 0) => 
+
const initializeArrayWithRange = (end, start = 0) =>
   Array.from({ length: (end + 1) - start }).map((v, i) => i + start);
 // initializeArrayWithRange(5) -> [0,1,2,3,4,5]
 // initializeArrayWithRange(7, 3) -> [3,4,5,6,7]
@@ -444,7 +464,7 @@ You can omit value to use a default value of 0.


mapObject

Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the mapped value.

Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new Array to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations).

-
const mapObject = (arr, fn) => 
+
const mapObject = (arr, fn) =>
   (a => (a = [arr, arr.map(fn)], a[0].reduce( (acc,val,ind) => (acc[val] = a[1][ind], acc), {}) )) ( );
 /*
 const squareIt = arr => mapObject(arr, a => a*a)
@@ -475,7 +495,7 @@ Use Array.length = 0 to mutate the passed in an array by resetting
 
const pull = (arr, ...args) => {
   let argState = Array.isArray(args[0]) ? args[0] : args;
   let pulled = arr.filter((v, i) => !argState.includes(v));
-  arr.length = 0; 
+  arr.length = 0;
   pulled.forEach(v => arr.push(v));
 };
 
@@ -496,7 +516,7 @@ Use Array.push() to keep track of pulled values

let removed = []; let pulled = arr.map((v, i) => pullArr.includes(i) ? removed.push(v) : v) .filter((v, i) => !pullArr.includes(i)) - arr.length = 0; + arr.length = 0; pulled.forEach(v => arr.push(v)); return removed; } @@ -513,7 +533,7 @@ Use Array.push() to keep track of pulled values

Use Array.length = 0 to mutate the passed in an array by resetting it's length to zero and Array.push() to re-populate it with only the pulled values. Use Array.push() to keep track of pulled values

const pullAtValue = (arr, pullArr) => {
-  let removed = [], 
+  let removed = [],
     pushToRemove = arr.forEach((v, i) => pullArr.includes(v) ? removed.push(v) : v),
     mutateTo = arr.filter((v, i) => !pullArr.includes(v));
   arr.length = 0;
@@ -825,7 +845,7 @@ If num falls within the range, return num.
 Otherwise, return the nearest number in the range.

const clampNumber = (num, lower, upper) => {
   if(lower > upper) upper = [lower, lower = upper][0];
-  return (num>=lower && num<=upper) ? num : ((num < lower) ? lower : upper) 
+  return (num>=lower && num<=upper) ? num : ((num < lower) ? lower : upper)
 }
 // clampNumber(2, 3, 5) -> 3
 // clampNumber(1, -1, -5) -> -1
@@ -920,7 +940,7 @@ If the second parameter, end, is not specified, the range is consid
 

isArmstrongNumber

Checks if the given number is an Armstrong number or not.

Convert the given number into an 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.

-
const isArmstrongNumber = digits => 
+
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
@@ -1000,13 +1020,13 @@ Then, split('') into individual characters, reverse(),
 

Generates primes up to a given number, using the Sieve of Eratosthenes.

Generate an array from 2 to the given number. Use Array.filter() to filter out the values divisible by any number from 2 to the square root of the provided number.

const primes = num => {
-  let arr =  Array.from({length:num-1}).map((x,i)=> i+2), 
+  let arr =  Array.from({length:num-1}).map((x,i)=> i+2),
     sqroot  = Math.floor(Math.sqrt(num)),
     numsTillSqroot  = Array.from({length:sqroot-1}).map((x,i)=> i+2);
   numsTillSqroot.forEach(x => arr = arr.filter(y => ((y%x)!==0)||(y==x)));
-  return arr; 
+  return arr;
 }
-// primes(10) -> [2,3,5,7] 
+// primes(10) -> [2,3,5,7]
 

randomIntegerInRange

Returns a random integer in the specified range.

diff --git a/static-parts/index-start.html b/static-parts/index-start.html index b81e02d7a..cb8bab170 100644 --- a/static-parts/index-start.html +++ b/static-parts/index-start.html @@ -23,8 +23,8 @@ Array.from(node.parentElement.parentElement.children).forEach(x => x.tagName == 'H3' ? (toRemove.style.display = (remove ? 'none' : ''), toRemove = x, remove = true) : (x.style.display == '' ? remove = false : remove=remove)); } - const pres = document.querySelectorAll("pre"); - pres.forEach(element => { + const snippets = document.querySelectorAll("pre"); + snippets.forEach(element => { const button = document.createElement("button"); button.innerHTML = "Copy to clipboard"; element.parentElement.appendChild(button); @@ -32,8 +32,8 @@ button.addEventListener ("click", function() { //The following regex removes all the comments from the snippet const text = element.textContent.replace(/\/\*(.|[\r\n])*?\*\//g, '').replace(/\/\/.*/gm, ''); - // Apparently you can copy variable to clipboard so you need to create text input element, - // give it a value, copy it and then remove it + // Apparently you can't copy a variable to clipboard so you need to create text input element, + // give it a value, copy it and then remove it from DOM. const textArea = document.createElement("textarea"); textArea.value = text; document.body.appendChild(textArea); From 5d10b73337082785a2df026a456b7041a5c3cbb7 Mon Sep 17 00:00:00 2001 From: Pl4gue Date: Sat, 23 Dec 2017 17:34:12 +0100 Subject: [PATCH 15/48] Delete unnecessary js file --- docs/bundle.js | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 docs/bundle.js diff --git a/docs/bundle.js b/docs/bundle.js deleted file mode 100644 index 009dec509..000000000 --- a/docs/bundle.js +++ /dev/null @@ -1,20 +0,0 @@ -var pres = document.querySelectorAll("pre"); -pres.forEach(element => { - const button = document.createElement("button"); - button.innerHTML = "Copy to clipboard"; - element.parentElement.appendChild(button); - - button.addEventListener ("click", function() { - //The following regex removes all the comments from the snippet - const text = element.textContent.replace(/\/\*(.|[\r\n])*?\*\//g, '').replace(/\/\/.*/gm, ''); - // Apparently you can copy variable to clipboard so you need to create text input element, - // give it a value, copy it and then remove it - const textArea = document.createElement("textarea"); - textArea.value = text; - document.body.appendChild(textArea); - textArea.select(); - document.execCommand("Copy"); - document.body.removeChild(textArea); - console.log(`copied: ${text}`); - }); -}); \ No newline at end of file From 469966e8fedfac9f2ac98d41e285e6e64063095f Mon Sep 17 00:00:00 2001 From: Pl4gue Date: Sat, 23 Dec 2017 17:34:39 +0100 Subject: [PATCH 16/48] Delete unnecessary js file --- static-parts/index-end.html | 1 - 1 file changed, 1 deletion(-) diff --git a/static-parts/index-end.html b/static-parts/index-end.html index 1b89d551a..2dd2aae7e 100644 --- a/static-parts/index-end.html +++ b/static-parts/index-end.html @@ -5,6 +5,5 @@
- From 0a842764582d0e3602fcd0fbd6ad46a60318ddf6 Mon Sep 17 00:00:00 2001 From: Pl4gue Date: Sat, 23 Dec 2017 17:34:49 +0100 Subject: [PATCH 17/48] Fix trailing empty lines --- static-parts/index-start.html | 45 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/static-parts/index-start.html b/static-parts/index-start.html index 1da0a0a70..3a926ab47 100644 --- a/static-parts/index-start.html +++ b/static-parts/index-start.html @@ -14,11 +14,10 @@ - - +

 30 seconds of code From 4bd0df64969cb72dfbfe3506ac45ef65fb8d36d1 Mon Sep 17 00:00:00 2001 From: Pl4gue Date: Sat, 23 Dec 2017 17:37:47 +0100 Subject: [PATCH 18/48] rebuild --- docs/index.html | 68 ++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/index.html b/docs/index.html index 12e0b5d12..07111b089 100644 --- a/docs/index.html +++ b/docs/index.html @@ -14,11 +14,10 @@ - - +

 30 seconds of code @@ -304,7 +305,7 @@ arrayMax([1,2,4]) // -> 4

Use Array.reduce() and the lcm formula (uses recursion) to calculate the lowest common multiple of an array of numbers.

const arrayLcm = arr =>{
   const gcd = (x, y) => !y ? x : gcd(y, x % y);
-  const lcm = (x, y) => (x*y)/gcd(x, y);
+  const lcm = (x, y) => (x*y)/gcd(x, y); 
   return arr.reduce((a,b) => lcm(a,b));
 }
 // arrayLcm([1,2,3,4,5]) -> 60
@@ -448,7 +449,7 @@ Use Array.reduce() to create an object, where the keys are produced
 

Initializes an array containing the numbers in the specified range where start and end are inclusive.

Use Array((end + 1) - start) to create an array of the desired length, Array.map() to fill with the desired values in a range. You can omit start to use a default value of 0.

-
const initializeArrayWithRange = (end, start = 0) =>
+
const initializeArrayWithRange = (end, start = 0) => 
   Array.from({ length: (end + 1) - start }).map((v, i) => i + start);
 // initializeArrayWithRange(5) -> [0,1,2,3,4,5]
 // initializeArrayWithRange(7, 3) -> [3,4,5,6,7]
@@ -475,7 +476,7 @@ You can omit value to use a default value of 0.


mapObject

Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the mapped value.

Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new Array to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations).

-
const mapObject = (arr, fn) =>
+
const mapObject = (arr, fn) => 
   (a => (a = [arr, arr.map(fn)], a[0].reduce( (acc,val,ind) => (acc[val] = a[1][ind], acc), {}) )) ( );
 /*
 const squareIt = arr => mapObject(arr, a => a*a)
@@ -506,7 +507,7 @@ Use Array.length = 0 to mutate the passed in an array by resetting
 
const pull = (arr, ...args) => {
   let argState = Array.isArray(args[0]) ? args[0] : args;
   let pulled = arr.filter((v, i) => !argState.includes(v));
-  arr.length = 0;
+  arr.length = 0; 
   pulled.forEach(v => arr.push(v));
 };
 
@@ -527,7 +528,7 @@ Use Array.push() to keep track of pulled values

let removed = []; let pulled = arr.map((v, i) => pullArr.includes(i) ? removed.push(v) : v) .filter((v, i) => !pullArr.includes(i)) - arr.length = 0; + arr.length = 0; pulled.forEach(v => arr.push(v)); return removed; } @@ -544,7 +545,7 @@ Use Array.push() to keep track of pulled values

Use Array.length = 0 to mutate the passed in an array by resetting it's length to zero and Array.push() to re-populate it with only the pulled values. Use Array.push() to keep track of pulled values

const pullAtValue = (arr, pullArr) => {
-  let removed = [],
+  let removed = [], 
     pushToRemove = arr.forEach((v, i) => pullArr.includes(v) ? removed.push(v) : v),
     mutateTo = arr.filter((v, i) => !pullArr.includes(v));
   arr.length = 0;
@@ -856,7 +857,7 @@ If num falls within the range, return num.
 Otherwise, return the nearest number in the range.

const clampNumber = (num, lower, upper) => {
   if(lower > upper) upper = [lower, lower = upper][0];
-  return (num>=lower && num<=upper) ? num : ((num < lower) ? lower : upper)
+  return (num>=lower && num<=upper) ? num : ((num < lower) ? lower : upper) 
 }
 // clampNumber(2, 3, 5) -> 3
 // clampNumber(1, -1, -5) -> -1
@@ -951,7 +952,7 @@ If the second parameter, end, is not specified, the range is consid
 

isArmstrongNumber

Checks if the given number is an Armstrong number or not.

Convert the given number into an 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.

-
const isArmstrongNumber = digits =>
+
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
@@ -1031,13 +1032,13 @@ Then, split('') into individual characters, reverse(),
 

Generates primes up to a given number, using the Sieve of Eratosthenes.

Generate an array from 2 to the given number. Use Array.filter() to filter out the values divisible by any number from 2 to the square root of the provided number.

const primes = num => {
-  let arr =  Array.from({length:num-1}).map((x,i)=> i+2),
+  let arr =  Array.from({length:num-1}).map((x,i)=> i+2), 
     sqroot  = Math.floor(Math.sqrt(num)),
     numsTillSqroot  = Array.from({length:sqroot-1}).map((x,i)=> i+2);
   numsTillSqroot.forEach(x => arr = arr.filter(y => ((y%x)!==0)||(y==x)));
-  return arr;
+  return arr; 
 }
-// primes(10) -> [2,3,5,7]
+// primes(10) -> [2,3,5,7] 
 

randomIntegerInRange

Returns a random integer in the specified range.

@@ -1432,7 +1433,6 @@ Use Number() to check if the coercion holds.

- From f59259db0de6ece79e02d03b5800614a3e32cd0d Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 23 Dec 2017 19:13:32 +0000 Subject: [PATCH 19/48] Travis build: 209 --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ docs/index.html | 27 +++++++++++++++++++++++++++ tag_database | 2 ++ 3 files changed, 69 insertions(+) diff --git a/README.md b/README.md index 0caf638f1..1a47e933c 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,10 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) +### _Uncategorized_ +* [`repeatString`](#repeatstring) +* [`toKebabCase`](#tokebabcase) + ## Adapter ### call @@ -2289,6 +2293,42 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == // validateNumber('10') -> true ``` +[⬆ back to top](#table-of-contents) +## _Uncategorized_ + +### repeatString + +Repeats a string n times using `String.repeat()` + +If no string is provided the default is `""` and the default number of times is 2. + +```js +const repeatString = (str="",num=2) => { + return num >= 0 ? str.repeat(num) : str; +} +// repeatString("abc",3) -> 'abcabcabc' +// repeatString("abc") -> 'abcabc' +``` + +[⬆ back to top](#table-of-contents) + +### toKebabCase + +Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). +Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes. + +```js +const toKebabCase = str => { + str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-'); + return str.startsWith('-') ? str.slice(1,str.length) : str; +} +// toKebabCase("camelCase") -> 'camel-case' +// toKebabCase("some text") -> 'some-text' +// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' +// toKebabCase("AllThe-small Things") -> "all-the-small-things" +``` + [⬆ back to top](#table-of-contents) ## Credits diff --git a/docs/index.html b/docs/index.html index ee176bf7d..9e3aebd82 100644 --- a/docs/index.html +++ b/docs/index.html @@ -206,6 +206,10 @@ UUIDGenerator validateNumber +

Uncategorized +

repeatString +toKebabCase +
 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

@@ -1403,6 +1407,29 @@ Use Number() to check if the coercion holds.

const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
 // validateNumber('10') -> true
 
+

Uncategorized

+

repeatString

+

Repeats a string n times using String.repeat()

+

If no string is provided the default is "" and the default number of times is 2.

+
const repeatString = (str="",num=2) => {
+    return num >= 0 ? str.repeat(num) : str;
+}
+// repeatString("abc",3) -> 'abcabcabc'
+// repeatString("abc") -> 'abcabc'
+
+

toKebabCase

+

Converts a string to kebab case. +Use replace() to add spaces before capital letters, convert toLowerCase(), then replace() underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes.

+
const toKebabCase = str => {
+    str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-');
+    return str.startsWith('-') ? str.slice(1,str.length) : str;
+}
+// toKebabCase("camelCase") -> 'camel-case'
+// toKebabCase("some text") -> 'some-text'
+// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens'
+// toKebabCase("AllThe-small Things") -> "all-the-small-things"
+

30 seconds of code is licensed under the CC0-1.0 license.
Icons made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY.
Ribbon made by Tim Holman is licensed by The MIT License
Built with the mini.css framework.

diff --git a/tag_database b/tag_database index db820842c..573e17441 100644 --- a/tag_database +++ b/tag_database @@ -97,6 +97,7 @@ randomNumberInRange:math readFileLines:node redirect:browser remove:array +repeatString:uncategorized reverseString:string RGBToHex:utility round:math @@ -120,6 +121,7 @@ timeTaken:utility toCamelCase:string toDecimalMark:utility toEnglishDate:date +toKebabCase:uncategorized toOrdinalSuffix:utility truncateString:string truthCheckCollection:object From 3e4b0e96e3a535424437d75b0581f5bb2f847e50 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 23 Dec 2017 23:39:57 +0200 Subject: [PATCH 20/48] Tags --- tag_database | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tag_database b/tag_database index 573e17441..9663c2aba 100644 --- a/tag_database +++ b/tag_database @@ -97,7 +97,7 @@ randomNumberInRange:math readFileLines:node redirect:browser remove:array -repeatString:uncategorized +repeatString:string reverseString:string RGBToHex:utility round:math @@ -121,7 +121,7 @@ timeTaken:utility toCamelCase:string toDecimalMark:utility toEnglishDate:date -toKebabCase:uncategorized +toKebabCase:string toOrdinalSuffix:utility truncateString:string truthCheckCollection:object From 349395d5e7dec30ac9ba8ebed0277d94dd442c12 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 23 Dec 2017 21:41:50 +0000 Subject: [PATCH 21/48] Travis build: 211 --- README.md | 77 ++++++++++++++++++++++++------------------------- docs/index.html | 51 +++++++++++++++----------------- 2 files changed, 61 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 1a47e933c..c8a3469be 100644 --- a/README.md +++ b/README.md @@ -142,9 +142,11 @@ * [`countVowels`](#countvowels) * [`escapeRegExp`](#escaperegexp) * [`fromCamelCase`](#fromcamelcase) +* [`repeatString`](#repeatstring) * [`reverseString`](#reversestring) * [`sortCharactersInString`](#sortcharactersinstring) * [`toCamelCase`](#tocamelcase) +* [`toKebabCase`](#tokebabcase) * [`truncateString`](#truncatestring) * [`words`](#words) @@ -167,10 +169,6 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) -### _Uncategorized_ -* [`repeatString`](#repeatstring) -* [`toKebabCase`](#tokebabcase) - ## Adapter ### call @@ -1961,6 +1959,22 @@ const fromCamelCase = (str, separator = '_') => [⬆ back to top](#table-of-contents) +### repeatString + +Repeats a string n times using `String.repeat()` + +If no string is provided the default is `""` and the default number of times is 2. + +```js +const repeatString = (str="",num=2) => { + return num >= 0 ? str.repeat(num) : str; +} +// repeatString("abc",3) -> 'abcabcabc' +// repeatString("abc") -> 'abcabc' +``` + +[⬆ back to top](#table-of-contents) + ### reverseString Reverses a string. @@ -2006,6 +2020,25 @@ const toCamelCase = str => [⬆ back to top](#table-of-contents) +### toKebabCase + +Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). +Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes. + +```js +const toKebabCase = str => { + str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-'); + return str.startsWith('-') ? str.slice(1,str.length) : str; +} +// toKebabCase("camelCase") -> 'camel-case' +// toKebabCase("some text") -> 'some-text' +// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' +// toKebabCase("AllThe-small Things") -> "all-the-small-things" +``` + +[⬆ back to top](#table-of-contents) + ### truncateString Truncates a string up to a specified length. @@ -2293,42 +2326,6 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == // validateNumber('10') -> true ``` -[⬆ back to top](#table-of-contents) -## _Uncategorized_ - -### repeatString - -Repeats a string n times using `String.repeat()` - -If no string is provided the default is `""` and the default number of times is 2. - -```js -const repeatString = (str="",num=2) => { - return num >= 0 ? str.repeat(num) : str; -} -// repeatString("abc",3) -> 'abcabcabc' -// repeatString("abc") -> 'abcabc' -``` - -[⬆ back to top](#table-of-contents) - -### toKebabCase - -Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). -Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens. -Also check if a string starts with a hyphen and remove it if yes. - -```js -const toKebabCase = str => { - str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-'); - return str.startsWith('-') ? str.slice(1,str.length) : str; -} -// toKebabCase("camelCase") -> 'camel-case' -// toKebabCase("some text") -> 'some-text' -// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' -// toKebabCase("AllThe-small Things") -> "all-the-small-things" -``` - [⬆ back to top](#table-of-contents) ## Credits diff --git a/docs/index.html b/docs/index.html index 9e3aebd82..bcb9d5685 100644 --- a/docs/index.html +++ b/docs/index.html @@ -181,9 +181,11 @@ countVowels escapeRegExp fromCamelCase +repeatString reverseString sortCharactersInString toCamelCase +toKebabCase truncateString words @@ -206,10 +208,6 @@ UUIDGenerator validateNumber -

Uncategorized -

repeatString -toKebabCase -
 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

@@ -1225,6 +1223,15 @@ Omit the second argument to use a default separator of _.

// fromCamelCase('someLabelThatNeedsToBeCamelized', '-') -> 'some-label-that-needs-to-be-camelized' // fromCamelCase('someJavascriptProperty', '_') -> 'some_javascript_property'
+

repeatString

+

Repeats a string n times using String.repeat()

+

If no string is provided the default is "" and the default number of times is 2.

+
const repeatString = (str="",num=2) => {
+    return num >= 0 ? str.repeat(num) : str;
+}
+// repeatString("abc",3) -> 'abcabcabc'
+// repeatString("abc") -> 'abcabc'
+

reverseString

Reverses a string.

Use split('') and Array.reverse() to reverse the order of the characters in the string. @@ -1249,6 +1256,19 @@ Combine characters to get a string using join('').

// toCamelCase("some-javascript-property") -> 'someJavascriptProperty' // toCamelCase("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens'
+

toKebabCase

+

Converts a string to kebab case. +Use replace() to add spaces before capital letters, convert toLowerCase(), then replace() underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes.

+
const toKebabCase = str => {
+    str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-');
+    return str.startsWith('-') ? str.slice(1,str.length) : str;
+}
+// toKebabCase("camelCase") -> 'camel-case'
+// toKebabCase("some text") -> 'some-text'
+// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens'
+// toKebabCase("AllThe-small Things") -> "all-the-small-things"
+

truncateString

Truncates a string up to a specified length.

Determine if the string's length is greater than num. @@ -1407,29 +1427,6 @@ Use Number() to check if the coercion holds.

const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
 // validateNumber('10') -> true
 
-

Uncategorized

-

repeatString

-

Repeats a string n times using String.repeat()

-

If no string is provided the default is "" and the default number of times is 2.

-
const repeatString = (str="",num=2) => {
-    return num >= 0 ? str.repeat(num) : str;
-}
-// repeatString("abc",3) -> 'abcabcabc'
-// repeatString("abc") -> 'abcabc'
-
-

toKebabCase

-

Converts a string to kebab case. -Use replace() to add spaces before capital letters, convert toLowerCase(), then replace() underscores and spaces with hyphens. -Also check if a string starts with a hyphen and remove it if yes.

-
const toKebabCase = str => {
-    str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-');
-    return str.startsWith('-') ? str.slice(1,str.length) : str;
-}
-// toKebabCase("camelCase") -> 'camel-case'
-// toKebabCase("some text") -> 'some-text'
-// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens'
-// toKebabCase("AllThe-small Things") -> "all-the-small-things"
-

30 seconds of code is licensed under the CC0-1.0 license.
Icons made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY.
Ribbon made by Tim Holman is licensed by The MIT License
Built with the mini.css framework.

From 33ab9be52973b98dcbab0557ca291b5b25dce4f8 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 23 Dec 2017 22:05:28 +0000 Subject: [PATCH 22/48] Travis build: 215 --- README.md | 18 ++++++++++++++++++ docs/index.html | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index c8a3469be..6786ca4aa 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ * [`sortCharactersInString`](#sortcharactersinstring) * [`toCamelCase`](#tocamelcase) * [`toKebabCase`](#tokebabcase) +* [`toSnakeCase`](#tosnakecase) * [`truncateString`](#truncatestring) * [`words`](#words) @@ -2039,6 +2040,23 @@ const toKebabCase = str => { [⬆ back to top](#table-of-contents) +### toSnakeCase + +Converts a string to snakecase. + +Use `replace()` to add underscores before capital letters, convert `toLowerCase()`, then `replace()` hyphens and spaces with underscores. + +```js +const toSnakeCase = str => + str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-_]+/g, '_').toLowerCase(); +// toSnakeCase("camelCase") -> 'camel_case' +// toSnakeCase("some text") -> 'some_text' +// toSnakeCase("some-javascript-property") -> 'some_javascript_property' +// toSnakeCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some_mixed_string_with_spaces_underscores_and_hyphens' +``` + +[⬆ back to top](#table-of-contents) + ### truncateString Truncates a string up to a specified length. diff --git a/docs/index.html b/docs/index.html index f4427854c..9b5808ae9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -208,6 +208,7 @@ sortCharactersInString toCamelCase toKebabCase +toSnakeCase truncateString words @@ -1291,6 +1292,16 @@ Also check if a string starts with a hyphen and remove it if yes.

// toKebabCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some-mixed-string-with-spaces-underscores-and-hyphens' // toKebabCase("AllThe-small Things") -> "all-the-small-things"
+

toSnakeCase

+

Converts a string to snakecase.

+

Use replace() to add underscores before capital letters, convert toLowerCase(), then replace() hyphens and spaces with underscores.

+
const toSnakeCase = str =>
+  str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-_]+/g, '_').toLowerCase();
+// toSnakeCase("camelCase") -> 'camel_case'
+// toSnakeCase("some text") -> 'some_text'
+// toSnakeCase("some-javascript-property") -> 'some_javascript_property'
+// toSnakeCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some_mixed_string_with_spaces_underscores_and_hyphens'
+

truncateString

Truncates a string up to a specified length.

Determine if the string's length is greater than num. From 175e127ab5dde527719dc32382dc8a3dafdfbfb1 Mon Sep 17 00:00:00 2001 From: Michael Gutman Date: Sun, 24 Dec 2017 01:28:52 -0500 Subject: [PATCH 23/48] ADD: negate.md --- snippets/negate.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 snippets/negate.md diff --git a/snippets/negate.md b/snippets/negate.md new file mode 100644 index 000000000..52cbd1cb6 --- /dev/null +++ b/snippets/negate.md @@ -0,0 +1,12 @@ +### negate + +Negates a predicate function. + +Take a predicate and apply `not` to it with its arguments. + +```js +const negate = predicate => (...args) => !predicate(...args) + +// filter([1, 2, 3, 4, 5, 6], negate(isEven)); +// => [1, 3, 5] +``` From 552830dea228ed2e20c24e5faeb26af44b4679bb Mon Sep 17 00:00:00 2001 From: Michael Gutman Date: Sun, 24 Dec 2017 01:36:12 -0500 Subject: [PATCH 24/48] Fixed styling --- snippets/negate.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/snippets/negate.md b/snippets/negate.md index 52cbd1cb6..d44b4f4dc 100644 --- a/snippets/negate.md +++ b/snippets/negate.md @@ -2,10 +2,12 @@ Negates a predicate function. -Take a predicate and apply `not` to it with its arguments. +Take a predicate function and apply `not` to it with its arguments. ```js -const negate = predicate => (...args) => !predicate(...args) +const negate = func => (...args) => { + return !func(...args); +} // filter([1, 2, 3, 4, 5, 6], negate(isEven)); // => [1, 3, 5] From 353c05904eb9ef648eed34f1e5dc522381128124 Mon Sep 17 00:00:00 2001 From: Michael Gutman Date: Sun, 24 Dec 2017 01:48:04 -0500 Subject: [PATCH 25/48] Added second example --- snippets/negate.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/negate.md b/snippets/negate.md index d44b4f4dc..c847a489a 100644 --- a/snippets/negate.md +++ b/snippets/negate.md @@ -9,6 +9,6 @@ const negate = func => (...args) => { return !func(...args); } -// filter([1, 2, 3, 4, 5, 6], negate(isEven)); -// => [1, 3, 5] +// filter([1, 2, 3, 4, 5, 6], negate(isEven)) -> [1, 3, 5] +// negate(isOdd)(1) -> false ``` From 4b339020b075d4b163906ecdaa3e45c09b409c42 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 13:09:23 +0530 Subject: [PATCH 26/48] Snippet to detect device type --- snippets/detectDeviceType.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 snippets/detectDeviceType.md diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md new file mode 100644 index 000000000..fcf4ea741 --- /dev/null +++ b/snippets/detectDeviceType.md @@ -0,0 +1,7 @@ +### detectDeviceType + +Detects weather the website is being opened in a mobile device or a desktop + +```js +const detectDevice = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; +``` \ No newline at end of file From 3af61ce755232290338823adff877eed34a2db6f Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 13:10:31 +0530 Subject: [PATCH 27/48] Fixed typo and added examples --- snippets/detectDeviceType.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md index fcf4ea741..26123a32a 100644 --- a/snippets/detectDeviceType.md +++ b/snippets/detectDeviceType.md @@ -3,5 +3,8 @@ Detects weather the website is being opened in a mobile device or a desktop ```js -const detectDevice = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; +const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; + +detectDeviceType() -> "Mobile" +detectDeviceType() -> "Desktop" ``` \ No newline at end of file From 0afd7a8777b99233122e3d6792a07dff217fa7f9 Mon Sep 17 00:00:00 2001 From: lvzhenbang Date: Sun, 24 Dec 2017 17:50:24 +0800 Subject: [PATCH 28/48] [bug] change Array.slice() for String.slice() useage: Array.slice() should be changed to String.slice() --- snippets/extendHex.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/extendHex.md b/snippets/extendHex.md index bda2cdd5e..8c7773c5e 100644 --- a/snippets/extendHex.md +++ b/snippets/extendHex.md @@ -3,7 +3,7 @@ Extends a 3-digit color code to a 6-digit color code. Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form. -`Array.slice()` is used to remove `#` from string start since it's added once. +`String.slice()` is used to remove `#` from string start since it's added once. ```js const extendHex = shortHex => '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('') From d158c61b7b798ab0d36bc1b6719b2e3f74ce9e54 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 24 Dec 2017 13:44:04 +0200 Subject: [PATCH 29/48] Update negate.md --- snippets/negate.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/snippets/negate.md b/snippets/negate.md index c847a489a..812b24efb 100644 --- a/snippets/negate.md +++ b/snippets/negate.md @@ -5,10 +5,7 @@ Negates a predicate function. Take a predicate function and apply `not` to it with its arguments. ```js -const negate = func => (...args) => { - return !func(...args); -} - +const negate = func => (...args) => !fun(...args); // filter([1, 2, 3, 4, 5, 6], negate(isEven)) -> [1, 3, 5] // negate(isOdd)(1) -> false ``` From 6ca563fcea9d7896fdbf81492510264fe8591e8b Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 24 Dec 2017 13:49:11 +0200 Subject: [PATCH 30/48] Update detectDeviceType.md --- snippets/detectDeviceType.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md index 26123a32a..b2822a458 100644 --- a/snippets/detectDeviceType.md +++ b/snippets/detectDeviceType.md @@ -1,10 +1,11 @@ ### detectDeviceType -Detects weather the website is being opened in a mobile device or a desktop +Detects wether the website is being opened in a mobile device or a desktop/laptop. + +Use a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop. ```js const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; - -detectDeviceType() -> "Mobile" -detectDeviceType() -> "Desktop" -``` \ No newline at end of file +// detectDeviceType() -> "Mobile" +// detectDeviceType() -> "Desktop" +``` From a9fd248343ff10abfff6ce59d77881d8bb5eb294 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sun, 24 Dec 2017 12:06:52 +0000 Subject: [PATCH 31/48] Travis build: 224 --- README.md | 35 ++++++++++++++++++++++++++++++++++- docs/index.html | 21 ++++++++++++++++++++- tag_database | 2 ++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6786ca4aa..99b31269b 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,10 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) +### _Uncategorized_ +* [`detectDeviceType`](#detectdevicetype) +* [`negate`](#negate) + ## Adapter ### call @@ -2120,7 +2124,7 @@ const coalesceFactory = valid => (...args) => args.find(valid); Extends a 3-digit color code to a 6-digit color code. Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form. -`Array.slice()` is used to remove `#` from string start since it's added once. +`String.slice()` is used to remove `#` from string start since it's added once. ```js const extendHex = shortHex => '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('') @@ -2344,6 +2348,35 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == // validateNumber('10') -> true ``` +[⬆ back to top](#table-of-contents) +## _Uncategorized_ + +### detectDeviceType + +Detects wether the website is being opened in a mobile device or a desktop/laptop. + +Use a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop. + +```js +const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; +// detectDeviceType() -> "Mobile" +// detectDeviceType() -> "Desktop" +``` + +[⬆ back to top](#table-of-contents) + +### negate + +Negates a predicate function. + +Take a predicate function and apply `not` to it with its arguments. + +```js +const negate = func => (...args) => !fun(...args); +// filter([1, 2, 3, 4, 5, 6], negate(isEven)) -> [1, 3, 5] +// negate(isOdd)(1) -> false +``` + [⬆ back to top](#table-of-contents) ## Credits diff --git a/docs/index.html b/docs/index.html index 9b5808ae9..e69391d07 100644 --- a/docs/index.html +++ b/docs/index.html @@ -231,6 +231,10 @@ UUIDGenerator validateNumber +

Uncategorized +

detectDeviceType +negate +
 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

@@ -1335,7 +1339,7 @@ Omit the second argument to use the default regex.


extendHex

Extends a 3-digit color code to a 6-digit color code.

Use Array.map(), split() and Array.join() to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form. -Array.slice() is used to remove # from string start since it's added once.

+String.slice() is used to remove # from string start since it's added once.

const extendHex = shortHex =>
   '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split('').map(x => x+x).join('')
 // extendHex('#03f') -> '#0033ff'
@@ -1460,6 +1464,21 @@ Use Number() to check if the coercion holds.

const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
 // validateNumber('10') -> true
 
+

Uncategorized

+

detectDeviceType

+

Detects wether the website is being opened in a mobile device or a desktop/laptop.

+

Use a regular expression to test the navigator.userAgent property to figure out if the device is a mobile device or a desktop/laptop.

+
const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop";
+// detectDeviceType() -> "Mobile"
+// detectDeviceType() -> "Desktop"
+
+

negate

+

Negates a predicate function.

+

Take a predicate function and apply not to it with its arguments.

+
const negate = func => (...args) => !fun(...args);
+// filter([1, 2, 3, 4, 5, 6], negate(isEven)) -> [1, 3, 5]
+// negate(isOdd)(1) -> false
+