Travis build: 559

This commit is contained in:
30secondsofcode
2018-09-29 13:47:39 +00:00
parent 096b937691
commit 1580116dd7
20 changed files with 194 additions and 20 deletions

146
README.md
View File

@ -251,10 +251,16 @@ average(1, 2, 3);
<details>
<summary>View contents</summary>
* [`dayOfYear`](#dayofyear)
* [`formatDuration`](#formatduration)
* [`getColonTimeFromDate`](#getcolontimefromdate)
* [`getDaysDiffBetweenDates`](#getdaysdiffbetweendates)
* [`getMeridiemSuffixOfInteger`](#getmeridiemsuffixofinteger)
* [`isAfterDate`](#isafterdate)
* [`isBeforeDate`](#isbeforedate)
* [`isSameDate`](#issamedate)
* [`maxDate`](#maxdate)
* [`minDate`](#mindate)
* [`tomorrow`](#tomorrow)
</details>
@ -4196,6 +4202,29 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
## ⏱️ Date
### dayOfYear
Gets the day of the year from a `Date` object.
Use `new Date()` and `Date.prototype.getFullYear()` to get the first day of the year as a `Date` object, subtract it from the provided `date` and divide with the milliseconds in each day to get the result.
Use `Math.floor()` to appropriately round the resulting day count to an integer.
```js
const dayOfYear = date =>
Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24);
```
<details>
<summary>Examples</summary>
```js
dayOfYear(new Date()); // 272
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### formatDuration
Returns the human readable format of the given number of milliseconds.
@ -4308,6 +4337,123 @@ getMeridiemSuffixOfInteger(25); // "1pm"
<br>[⬆ Back to top](#table-of-contents)
### isAfterDate
Check if a date is after another date.
Use the greater than operator (`>`) to check if the first date comes after the second one.
```js
const isAfterDate = (dateA, dateB) => dateA > dateB;
```
<details>
<summary>Examples</summary>
```js
isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### isBeforeDate
Check if a date is before another date.
Use the less than operator (`<`) to check if the first date comes before the second one.
```js
const isBeforeDate = (dateA, dateB) => dateA < dateB;
```
<details>
<summary>Examples</summary>
```js
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### isSameDate
Check if a date is the same as another date.
Use `Date.prototype.toISOString()` and strict equality checking (`===`) to check if the first date is the same as the second one.
```js
const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString();
```
<details>
<summary>Examples</summary>
```js
isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### maxDate
Returns the maximum of the given dates.
Use `Math.max.apply()` to find the maximum date value, `new Date()` to convert it to a `Date` object.
```js
const maxDate = (...dates) => new Date(Math.max.apply(null, ...dates));
```
<details>
<summary>Examples</summary>
```js
const array = [
new Date(2017, 4, 13),
new Date(2018, 2, 12),
new Date(2016, 0, 10),
new Date(2016, 0, 9)
];
maxDate(array); // 2018-03-11T22:00:00.000Z
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### minDate
Returns the minimum of the given dates.
Use `Math.min.apply()` to find the minimum date value, `new Date()` to convert it to a `Date` object.
```js
const minDate = (...dates) => new Date(Math.min.apply(null, ...dates));
```
<details>
<summary>Examples</summary>
```js
const array = [
new Date(2017, 4, 13),
new Date(2018, 2, 12),
new Date(2016, 0, 10),
new Date(2016, 0, 9)
];
minDate(array); // 2016-01-08T22:00:00.000Z
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### tomorrow
Results in a string representation of tomorrow's date.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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
```

View File

@ -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

View File

@ -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

View File

@ -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);
};
```

View File

@ -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));
};
```

View File

@ -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;
};

View File

@ -6,7 +6,7 @@ Use `Array.prototype.reduce()` to calculate how many numbers are below the value
```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

View File

@ -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