From 3197d6ddce65266d3b5cf7b7253d5124a6fea41c Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Mon, 18 Jun 2018 18:26:52 +0000 Subject: [PATCH] Travis build: 2161 --- README.md | 21 ++++++++++++--------- docs/beginner.html | 6 +++--- docs/date.html | 4 ++-- docs/function.html | 7 +++++-- docs/math.html | 12 ++++++------ snippets/compose.md | 5 ++++- snippets/degreesToRads.md | 2 +- snippets/getMeridiemSuffixOfInteger.md | 4 ++-- snippets/hz.md | 2 +- snippets/lcm.md | 2 +- snippets/luhnCheck.md | 2 +- snippets/percentile.md | 2 +- snippets/radsToDegrees.md | 2 +- 13 files changed, 40 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index ec2c86abc..74a94f17b 100644 --- a/README.md +++ b/README.md @@ -4060,8 +4060,8 @@ const getMeridiemSuffixOfInteger = num => : num === 12 ? 12 + 'pm' : num < 12 - ? num % 12 + 'am' - : num % 12 + 'pm'; + ? (num % 12) + 'am' + : (num % 12) + 'pm'; ```
@@ -4256,7 +4256,10 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); ```js const add5 = x => x + 5; const multiply = (x, y) => x * y; -const multiplyAndAdd5 = compose(add5, multiply); +const multiplyAndAdd5 = compose( + add5, + multiply +); multiplyAndAdd5(5, 2); // 15 ``` @@ -4472,7 +4475,7 @@ Omit the second argument, `iterations`, to use the default of 100 iterations. const hz = (fn, iterations = 100) => { const before = performance.now(); for (let i = 0; i < iterations; i++) fn(); - return 1000 * iterations / (performance.now() - before); + return (1000 * iterations) / (performance.now() - before); }; ``` @@ -4992,7 +4995,7 @@ Converts an angle from degrees to radians. Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians. ```js -const degreesToRads = deg => deg * Math.PI / 180.0; +const degreesToRads = deg => (deg * Math.PI) / 180.0; ```
@@ -5356,7 +5359,7 @@ The GCD formula uses recursion. ```js const lcm = (...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)); }; ``` @@ -5391,7 +5394,7 @@ const luhnCheck = num => { .reverse() .map(x => parseInt(x)); let lastDigit = arr.splice(0, 1)[0]; - let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0); + let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), 0); sum += lastDigit; return sum % 10 === 0; }; @@ -5492,7 +5495,7 @@ Use `Array.reduce()` to calculate how many numbers are below the value and how m ```js const percentile = (arr, val) => - 100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length; + (100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0)) / arr.length; ```
@@ -5564,7 +5567,7 @@ Converts an angle from radians to degrees. Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees. ```js -const radsToDegrees = rad => rad * 180.0 / Math.PI; +const radsToDegrees = rad => (rad * 180.0) / Math.PI; ```
diff --git a/docs/beginner.html b/docs/beginner.html index d96086dba..1467b9e6f 100644 --- a/docs/beginner.html +++ b/docs/beginner.html @@ -89,8 +89,8 @@ : num === 12 ? 12 + 'pm' : num < 12 - ? num % 12 + 'am' - : num % 12 + 'pm'; + ? (num % 12) + 'am' + : (num % 12) + 'pm';
getMeridiemSuffixOfInteger(0); // "12am"
 getMeridiemSuffixOfInteger(11); // "11am"
 getMeridiemSuffixOfInteger(13); // "1pm"
@@ -111,7 +111,7 @@
 
last([1, 2, 3]); // 3
 

lcm

Returns the least common multiple of two or more numbers.

Use the greatest common divisor (GCD) formula and the fact that lcm(x,y) = x * y / gcd(x,y) to determine the least common multiple. The GCD formula uses recursion.

const lcm = (...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));
 };
 
lcm(12, 7); // 84
diff --git a/docs/date.html b/docs/date.html
index f3696c334..15aac061e 100644
--- a/docs/date.html
+++ b/docs/date.html
@@ -106,8 +106,8 @@
     : num === 12
       ? 12 + 'pm'
       : num < 12
-        ? num % 12 + 'am'
-        : num % 12 + 'pm';
+        ? (num % 12) + 'am'
+        : (num % 12) + 'pm';
 
getMeridiemSuffixOfInteger(0); // "12am"
 getMeridiemSuffixOfInteger(11); // "11am"
 getMeridiemSuffixOfInteger(13); // "1pm"
diff --git a/docs/function.html b/docs/function.html
index 08c942a1b..c7ed24354 100644
--- a/docs/function.html
+++ b/docs/function.html
@@ -129,7 +129,10 @@ console.log<
 

compose

Performs right-to-left function composition.

Use Array.reduce() to perform right-to-left function composition. The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.

const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
 
const add5 = x => x + 5;
 const multiply = (x, y) => x * y;
-const multiplyAndAdd5 = compose(add5, multiply);
+const multiplyAndAdd5 = compose(
+  add5,
+  multiply
+);
 multiplyAndAdd5(5, 2); // 15
 

composeRight

Performs left-to-right function composition.

Use Array.reduce() to perform left-to-right function composition. The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.

const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
 
const add = (x, y) => x + y;
@@ -181,7 +184,7 @@ document.que
 

hz

Returns the number of times a function executed per second. hz is the unit for hertz, the unit of frequency defined as one cycle per second.

Use performance.now() to get the difference in milliseconds before and after the iteration loop to calculate the time elapsed executing the function iterations times. Return the number of cycles per second by converting milliseconds to seconds and dividing it by the time elapsed. Omit the second argument, iterations, to use the default of 100 iterations.

const hz = (fn, iterations = 100) => {
   const before = performance.now();
   for (let i = 0; i < iterations; i++) fn();
-  return 1000 * iterations / (performance.now() - before);
+  return (1000 * iterations) / (performance.now() - before);
 };
 
// 10,000 element array
 const numbers = Array(10000)
diff --git a/docs/math.html b/docs/math.html
index df2c1c179..e0c9bd222 100644
--- a/docs/math.html
+++ b/docs/math.html
@@ -103,7 +103,7 @@
 

clampNumber

Clamps num within the inclusive range specified by the boundary values a and b.

If num falls within the range, return num. Otherwise, return the nearest number in the range.

const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
 
clampNumber(2, 3, 5); // 3
 clampNumber(1, -1, -5); // -1
-

degreesToRads

Converts an angle from degrees to radians.

Use Math.PI and the degree to radian formula to convert the angle from degrees to radians.

const degreesToRads = deg => deg * Math.PI / 180.0;
+

degreesToRads

Converts an angle from degrees to radians.

Use Math.PI and the degree to radian formula to convert the angle from degrees to radians.

const degreesToRads = deg => (deg * Math.PI) / 180.0;
 
degreesToRads(90.0); // ~1.5708
 

digitize

Converts a number to an array of digits.

Convert the number to a string, using the spread operator (...) to build an array. Use Array.map() and parseInt() to transform each value to an integer.

const digitize = n => [...`${n}`].map(i => parseInt(i));
 
digitize(123); // [1, 2, 3]
@@ -187,7 +187,7 @@ own individual rating by supplying it as the third argument.
 
isPrime(11); // true
 

lcm

Returns the least common multiple of two or more numbers.

Use the greatest common divisor (GCD) formula and the fact that lcm(x,y) = x * y / gcd(x,y) to determine the least common multiple. The GCD formula uses recursion.

const lcm = (...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));
 };
 
lcm(12, 7); // 84
@@ -198,7 +198,7 @@ own individual rating by supplying it as the third argument.
     .reverse()
     .map(x => parseInt(x));
   let lastDigit = arr.splice(0, 1)[0];
-  let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0);
+  let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), 0);
   sum += lastDigit;
   return sum % 10 === 0;
 };
@@ -218,7 +218,7 @@ own individual rating by supplying it as the third argument.
 
minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2
 minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2
 

percentile

Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.

Use Array.reduce() to calculate how many numbers are below the value and how many are the same value and apply the percentile formula.

const percentile = (arr, val) =>
-  100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length;
+  (100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0)) / arr.length;
 
percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6); // 55
 

powerset

Returns the powerset of a given array of numbers.

Use Array.reduce() combined with Array.map() to iterate over elements and combine into an array containing all combinations.

const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))), [[]]);
 
powerset([1, 2]); // [[], [1], [2], [2,1]]
@@ -230,7 +230,7 @@ own individual rating by supplying it as the third argument.
   return arr;
 };
 
primes(10); // [2,3,5,7]
-

radsToDegrees

Converts an angle from radians to degrees.

Use Math.PI and the radian to degree formula to convert the angle from radians to degrees.

const radsToDegrees = rad => rad * 180.0 / Math.PI;
+

radsToDegrees

Converts an angle from radians to degrees.

Use Math.PI and the radian to degree formula to convert the angle from radians to degrees.

const radsToDegrees = rad => (rad * 180.0) / Math.PI;
 
radsToDegrees(Math.PI / 2); // 90
 

randomIntArrayInRange

Returns an array of n random integers in the specified range.

Use Array.from() to create an empty array of the specific length, Math.random() to generate a random number and map it to the desired range, using Math.floor() to make it an integer.

const randomIntArrayInRange = (min, max, n = 1) =>
   Array.from({ length: n }, () => Math.floor(Math.random() * (max - min + 1)) + min);
@@ -239,7 +239,7 @@ own individual rating by supplying it as the third argument.
 
randomIntegerInRange(0, 5); // 2
 

randomNumberInRange

Returns a random number in the specified range.

Use Math.random() to generate a random value, map it to the desired range using multiplication.

const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
 
randomNumberInRange(2, 10); // 6.0211363285087005
-

round

Rounds a number to a specified amount of digits.

Use Math.round() and template literals to round the number to the specified number of digits. Omit the second argument, decimals to round to an integer.

const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
+

round

Rounds a number to a specified amount of digits.

Use Math.round() and template literals to round the number to the specified number of digits. Omit the second argument, decimals to round to an integer.

const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
 
round(1.005, 2); // 1.01
 

sdbm

Hashes the input string into a whole number.

Use String.split('') and Array.reduce() to create a hash of the input string, utilizing bit shifting.

const sdbm = str => {
   let arr = str.split('');
diff --git a/snippets/compose.md b/snippets/compose.md
index 51574db5f..7df5ba250 100644
--- a/snippets/compose.md
+++ b/snippets/compose.md
@@ -12,6 +12,9 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
 ```js
 const add5 = x => x + 5;
 const multiply = (x, y) => x * y;
-const multiplyAndAdd5 = compose(add5, multiply);
+const multiplyAndAdd5 = compose(
+  add5,
+  multiply
+);
 multiplyAndAdd5(5, 2); // 15
 ```
diff --git a/snippets/degreesToRads.md b/snippets/degreesToRads.md
index ed3a2ee0e..90790765d 100644
--- a/snippets/degreesToRads.md
+++ b/snippets/degreesToRads.md
@@ -5,7 +5,7 @@ Converts an angle from degrees to radians.
 Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians.
 
 ```js
-const degreesToRads = deg => deg * Math.PI / 180.0;
+const degreesToRads = deg => (deg * Math.PI) / 180.0;
 ```
 
 ```js
diff --git a/snippets/getMeridiemSuffixOfInteger.md b/snippets/getMeridiemSuffixOfInteger.md
index ea153f7b2..9cf6e46c3 100644
--- a/snippets/getMeridiemSuffixOfInteger.md
+++ b/snippets/getMeridiemSuffixOfInteger.md
@@ -11,8 +11,8 @@ const getMeridiemSuffixOfInteger = num =>
     : num === 12
       ? 12 + 'pm'
       : num < 12
-        ? num % 12 + 'am'
-        : num % 12 + 'pm';
+        ? (num % 12) + 'am'
+        : (num % 12) + 'pm';
 ```
 
 ```js
diff --git a/snippets/hz.md b/snippets/hz.md
index 08cff5de6..c1e9c0ceb 100644
--- a/snippets/hz.md
+++ b/snippets/hz.md
@@ -11,7 +11,7 @@ Omit the second argument, `iterations`, to use the default of 100 iterations.
 const hz = (fn, iterations = 100) => {
   const before = performance.now();
   for (let i = 0; i < iterations; i++) fn();
-  return 1000 * iterations / (performance.now() - before);
+  return (1000 * iterations) / (performance.now() - before);
 };
 ```
 
diff --git a/snippets/lcm.md b/snippets/lcm.md
index 74f346af3..970e3083c 100644
--- a/snippets/lcm.md
+++ b/snippets/lcm.md
@@ -8,7 +8,7 @@ The GCD formula uses recursion.
 ```js
 const lcm = (...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));
 };
 ```
diff --git a/snippets/luhnCheck.md b/snippets/luhnCheck.md
index 69b09b113..9bffb5a79 100644
--- a/snippets/luhnCheck.md
+++ b/snippets/luhnCheck.md
@@ -15,7 +15,7 @@ const luhnCheck = num => {
     .reverse()
     .map(x => parseInt(x));
   let lastDigit = arr.splice(0, 1)[0];
-  let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0);
+  let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), 0);
   sum += lastDigit;
   return sum % 10 === 0;
 };
diff --git a/snippets/percentile.md b/snippets/percentile.md
index 3da948e0e..e0c74d73e 100644
--- a/snippets/percentile.md
+++ b/snippets/percentile.md
@@ -6,7 +6,7 @@ Use `Array.reduce()` to calculate how many numbers are below the value and how m
 
 ```js
 const percentile = (arr, val) =>
-  100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length;
+  (100 * arr.reduce((acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0)) / arr.length;
 ```
 
 ```js
diff --git a/snippets/radsToDegrees.md b/snippets/radsToDegrees.md
index d8dd54958..3cd4fa8d4 100644
--- a/snippets/radsToDegrees.md
+++ b/snippets/radsToDegrees.md
@@ -5,7 +5,7 @@ Converts an angle from radians to degrees.
 Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees.
 
 ```js
-const radsToDegrees = rad => rad * 180.0 / Math.PI;
+const radsToDegrees = rad => (rad * 180.0) / Math.PI;
 ```
 
 ```js