Travis build: 1023

This commit is contained in:
30secondsofcode
2018-01-04 12:28:05 +00:00
parent 00b3da7504
commit cdb2303156
4 changed files with 107 additions and 220 deletions

159
README.md
View File

@ -498,7 +498,6 @@ const spreadOver = fn => argsArr => fn(...argsArr);
```js ```js
const arrayMax = spreadOver(Math.max); const arrayMax = spreadOver(Math.max);
arrayMax([1, 2, 3]); // 3 arrayMax([1, 2, 3]); // 3
arrayMax([1, 2, 4]); // 4
``` ```
</details> </details>
@ -920,7 +919,7 @@ Initializes an array containing the numbers in the specified range where `start`
Use `Array(Math.ceil((end+1-start)/step)` to create an array of the desired length(the amounts of elements is equal to `(end-start)/step` or `(end+1-start)/step` for inclusive end), `Array.map()` to fill with the desired values in a range. Use `Array(Math.ceil((end+1-start)/step)` to create an array of the desired length(the amounts of elements is equal to `(end-start)/step` or `(end+1-start)/step` for inclusive end), `Array.map()` to fill with the desired values in a range.
You can omit `start` to use a default value of `0`. You can omit `start` to use a default value of `0`.
You can omit `step` to use a default value of `1`. You can omit `step` to use a default value of `1`.
```js ```js
const initializeArrayWithRange = (end, start = 0, step = 1) => const initializeArrayWithRange = (end, start = 0, step = 1) =>
Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start); Array.from({ length: Math.ceil((end + 1 - start) / step) }).map((v, i) => i * step + start);
@ -932,7 +931,7 @@ const initializeArrayWithRange = (end, start = 0, step = 1) =>
```js ```js
initializeArrayWithRange(5); // [0,1,2,3,4,5] initializeArrayWithRange(5); // [0,1,2,3,4,5]
initializeArrayWithRange(7, 3); // [3,4,5,6,7] initializeArrayWithRange(7, 3); // [3,4,5,6,7]
initializeArrayWithRange(9, 0, 2); //[0,2,4,6,8] initializeArrayWithRange(9, 0, 2); // [0,2,4,6,8]
``` ```
</details> </details>
@ -1009,7 +1008,6 @@ const isSorted = arr => {
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
isSorted([0, 1, 2, 3]); // 1
isSorted([0, 1, 2, 2]); // 1 isSorted([0, 1, 2, 2]); // 1
isSorted([4, 3, 2]); // -1 isSorted([4, 3, 2]); // -1
isSorted([4, 3, 5]); // 0 isSorted([4, 3, 5]); // 0
@ -1043,10 +1041,9 @@ const join = (arr, separator = ',', end = separator) =>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
join(); // '' join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'); // "pen,pineapple,apple&pen"
join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'); //"pen,pineapple,apple&pen" join(['pen', 'pineapple', 'apple', 'pen'], ','); // "pen,pineapple,apple,pen"
join(['pen', 'pineapple', 'apple', 'pen'], ','); //"pen,pineapple,apple,pen" join(['pen', 'pineapple', 'apple', 'pen']); // "pen,pineapple,apple,pen"
join(['pen', 'pineapple', 'apple', 'pen']); //"pen,pineapple,apple,pen"
``` ```
</details> </details>
@ -1106,7 +1103,7 @@ squareIt([1, 2, 3]); // { 1: 1, 2: 4, 3: 9 }
Returns the `n` maximum elements from the provided array. If `n` is greater than or equal to the provided array's length, then return the original array(sorted in descending order). Returns the `n` maximum elements from the provided array. If `n` is greater than or equal to the provided array's length, then return the original array(sorted in descending order).
Use `Array.sort()` combined with the spread operator (`...`) to create a shallow clone of the array and sort it in descending order. Use `Array.sort()` combined with the spread operator (`...`) to create a shallow clone of the array and sort it in descending order.
Use `Array.slice()` to get the specified number of elements. Use `Array.slice()` to get the specified number of elements.
Omit the second argument, `n`, to get a one-element array. Omit the second argument, `n`, to get a one-element array.
@ -1120,7 +1117,6 @@ const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
```js ```js
maxN([1, 2, 3]); // [3] maxN([1, 2, 3]); // [3]
maxN([1, 2, 3], 2); // [3,2] maxN([1, 2, 3], 2); // [3,2]
maxN([1, 2, 3], 4); // [3,2,1]
``` ```
</details> </details>
@ -1145,7 +1141,6 @@ const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
```js ```js
minN([1, 2, 3]); // [1] minN([1, 2, 3]); // [1]
minN([1, 2, 3], 2); // [1,2] minN([1, 2, 3], 2); // [1,2]
minN([1, 2, 3], 4); // [1,2,3]
``` ```
</details> </details>
@ -1223,13 +1218,8 @@ const pull = (arr, ...args) => {
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c']; let myArray = ['a', 'b', 'c', 'a', 'b', 'c'];
pull(myArray1, 'a', 'c'); pull(myArray, 'a', 'c'); // myArray = [ 'b', 'b' ]
console.log(myArray1); // [ 'b', 'b' ]
let myArray2 = ['a', 'b', 'c', 'a', 'b', 'c'];
pull(myArray2, ['a', 'c']);
console.log(myArray2); // [ 'b', 'b' ]
``` ```
</details> </details>
@ -1262,10 +1252,7 @@ const pullAtIndex = (arr, pullArr) => {
```js ```js
let myArray = ['a', 'b', 'c', 'd']; let myArray = ['a', 'b', 'c', 'd'];
let pulled = pullAtIndex(myArray, [1, 3]); let pulled = pullAtIndex(myArray, [1, 3]); // myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ]
console.log(myArray); // [ 'a', 'c' ]
console.log(pulled); // [ 'b', 'd' ]
``` ```
</details> </details>
@ -1297,9 +1284,7 @@ const pullAtValue = (arr, pullArr) => {
```js ```js
let myArray = ['a', 'b', 'c', 'd']; let myArray = ['a', 'b', 'c', 'd'];
let pulled = pullAtValue(myArray, ['b', 'd']); let pulled = pullAtValue(myArray, ['b', 'd']); // myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ]
console.log(myArray); // [ 'a', 'c' ]
console.log(pulled); // [ 'b', 'd' ]
``` ```
</details> </details>
@ -1487,8 +1472,7 @@ const shuffle = ([...arr]) => {
```js ```js
const foo = [1, 2, 3]; const foo = [1, 2, 3];
shuffle(foo); // [2,3,1] shuffle(foo); // [2,3,1], foo = [1,2,3]
console.log(foo); // [1,2,3]
``` ```
</details> </details>
@ -1871,8 +1855,7 @@ const detectDeviceType = () =>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
detectDeviceType(); // "Mobile" detectDeviceType(); // "Mobile" or "Desktop"
detectDeviceType(); // "Desktop"
``` ```
</details> </details>
@ -1905,8 +1888,8 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
```js ```js
// e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10} // e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10}
elementIsVisibleInViewport(el); // false // (not fully visible) elementIsVisibleInViewport(el); // false - (not fully visible)
elementIsVisibleInViewport(el, true); // true // (partially visible) elementIsVisibleInViewport(el, true); // true - (partially visible)
``` ```
</details> </details>
@ -2097,8 +2080,8 @@ redirect('https://google.com');
Runs a function in a separate thread by using a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), allowing long running functions to not block the UI. Runs a function in a separate thread by using a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), allowing long running functions to not block the UI.
Create a new `Worker` using a `Blob` object URL, the contents of which should be the stringified version of the supplied function. Create a new `Worker` using a `Blob` object URL, the contents of which should be the stringified version of the supplied function.
Immediately post the return value of calling the function back. Immediately post the return value of calling the function back.
Return a promise, listening for `onmessage` and `onerror` events and resolving the data posted back from the worker, or throwing an error. Return a promise, listening for `onmessage` and `onerror` events and resolving the data posted back from the worker, or throwing an error.
```js ```js
@ -2135,10 +2118,11 @@ const longRunningFunction = () => {
} }
return result; return result;
}; };
/*
// NOTE: Since the function is running in a different context, closures are not supported. NOTE: Since the function is running in a different context, closures are not supported.
// The function supplied to `runAsync` gets stringified, so everything becomes literal. The function supplied to `runAsync` gets stringified, so everything becomes literal.
// All variables and functions must be defined inside. All variables and functions must be defined inside.
*/
runAsync(longRunningFunction).then(console.log); // 209685000000 runAsync(longRunningFunction).then(console.log); // 209685000000
runAsync(() => 10 ** 3).then(console.log); // 1000 runAsync(() => 10 ** 3).then(console.log); // 1000
let outsideVariable = 50; let outsideVariable = 50;
@ -2331,9 +2315,8 @@ const formatDuration = ms => {
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
formatDuration(1001); // "1 second, 1 millisecond" formatDuration(1001); // '1 second, 1 millisecond'
formatDuration(343250555); // "3 days, 23 hours, 20 minutes, 50 seconds, 555 milliseconds" formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'
formatDuration(34325055574); // "397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds"
``` ```
</details> </details>
@ -2467,10 +2450,6 @@ chainAsync([
}, },
next => { next => {
console.log('1 second'); console.log('1 second');
setTimeout(next, 1000);
},
next => {
console.log('2 seconds');
} }
]); ]);
``` ```
@ -2552,8 +2531,8 @@ defer(console.log, 'a'), console.log('b'); // logs 'b' then 'a'
// Example B: // Example B:
document.querySelector('#someElement').innerHTML = 'Hello'; document.querySelector('#someElement').innerHTML = 'Hello';
longRunningFunction(); // the browser will not update the HTML until this has finished longRunningFunction(); //Browser will not update the HTML until this has finished
defer(longRunningFunction); // the browser will update the HTML then run the function defer(longRunningFunction); // Browser will update the HTML then run the function
``` ```
</details> </details>
@ -2610,7 +2589,7 @@ const memoize = fn => {
const anagramsCached = memoize(anagrams); const anagramsCached = memoize(anagrams);
anagramsCached('javascript'); // takes a long time anagramsCached('javascript'); // takes a long time
anagramsCached('javascript'); // returns virtually instantly since it's now cached anagramsCached('javascript'); // returns virtually instantly since it's now cached
console.log(anagramsCached.cache); // Map console.log(anagramsCached.cache); // The cached anagrams map
``` ```
</details> </details>
@ -2666,7 +2645,7 @@ const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.r
```js ```js
const delay = d => new Promise(r => setTimeout(r, d)); const delay = d => new Promise(r => setTimeout(r, d));
runPromisesInSeries([() => delay(1000), () => delay(2000)]); // //executes each promise sequentially, taking a total of 3 seconds to complete runPromisesInSeries([() => delay(1000), () => delay(2000)]); // Executes each promise sequentially, taking a total of 3 seconds to complete
``` ```
</details> </details>
@ -2770,7 +2749,6 @@ const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.
```js ```js
clampNumber(2, 3, 5); // 3 clampNumber(2, 3, 5); // 3
clampNumber(1, -1, -5); // -1 clampNumber(1, -1, -5); // -1
clampNumber(3, 2, 4); // 3
``` ```
</details> </details>
@ -2793,7 +2771,6 @@ const collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
```js ```js
collatz(8); // 4 collatz(8); // 4
collatz(5); // 16
``` ```
</details> </details>
@ -2869,8 +2846,6 @@ const elo = ([a, b], kFactor = 32) => {
```js ```js
elo([1200, 1200]); // [1216, 1184] elo([1200, 1200]); // [1216, 1184]
elo([1000, 2000]); // [1031.8991261061358, 1968.1008738938642]
elo([1500, 1000]); // [1501.7036868864648, 998.2963131135352]
elo([1200, 1200], 64); // [1232, 1168] elo([1200, 1200], 64); // [1232, 1168]
``` ```
@ -3070,10 +3045,10 @@ gcd(8, 36); // 4
### geometricProgression ### geometricProgression
Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive and the ratio between two terms is `step`. Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive and the ratio between two terms is `step`.
Returns an error if `step` equals `1`. Returns an error if `step` equals `1`.
Use `Array.from()`, `Math.log()` and `Math.floor()` to create an array of the desired length, `Array.map()` to fill with the desired values in a range. Use `Array.from()`, `Math.log()` and `Math.floor()` to create an array of the desired length, `Array.map()` to fill with the desired values in a range.
Omit the second argument, `start`, to use a default value of `1`. Omit the second argument, `start`, to use a default value of `1`.
Omit the third argument, `step`, to use a default value of `2`. Omit the third argument, `step`, to use a default value of `2`.
@ -3089,9 +3064,8 @@ const geometricProgression = (end, start = 1, step = 2) =>
```js ```js
geometricProgression(256); // [1, 2, 4, 8, 16, 32, 64, 128, 256] geometricProgression(256); // [1, 2, 4, 8, 16, 32, 64, 128, 256]
geometricProgression(256, 3); //[3, 6, 12, 24, 48, 96, 192] geometricProgression(256, 3); // [3, 6, 12, 24, 48, 96, 192]
geometricProgression(256, 1, 4); //[1, 4, 16, 64, 256] geometricProgression(256, 1, 4); // [1, 4, 16, 64, 256]
geometricProgression(256, 2, 1); //Gives error
``` ```
</details> </details>
@ -3124,7 +3098,7 @@ hammingDistance(2, 3); // 1
### howManyTimes ### howManyTimes
Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer. Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer.
Works for both negative and positive integers. Works for both negative and positive integers.
If `divisor` is `-1` or `1` return `Infinity`. If `divisor` is `-1` or `1` return `Infinity`.
@ -3149,13 +3123,10 @@ const howManyTimes = (num, divisor) => {
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
howManyTimes(100, 2); //2 howManyTimes(100, 2); // 2
howManyTimes(100, -2); //2 howManyTimes(100, 2.5); // 2
howManyTimes(100, 2.5); //2 howManyTimes(100, 0); // 0
howManyTimes(100, 3); //0 howManyTimes(100, -1); // Infinity
howManyTimes(100, 0); //0
howManyTimes(100, 1); //Infinity
howManyTimes(100, -1); //Infinity
``` ```
</details> </details>
@ -3210,7 +3181,6 @@ const isArmstrongNumber = digits =>
```js ```js
isArmstrongNumber(1634); // true isArmstrongNumber(1634); // true
isArmstrongNumber(371); // true
isArmstrongNumber(56); // false isArmstrongNumber(56); // false
``` ```
@ -3284,7 +3254,6 @@ const isPrime = num => {
```js ```js
isPrime(11); // true isPrime(11); // true
isPrime(12); // false
``` ```
</details> </details>
@ -3377,7 +3346,6 @@ const median = arr => {
```js ```js
median([5, 6, 50, 1, -5]); // 5 median([5, 6, 50, 1, -5]); // 5
median([0, 10, -2, 7]); // 3.5
``` ```
</details> </details>
@ -3571,10 +3539,7 @@ const solveRPN = rpn => {
```js ```js
solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5 solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5
solveRPN('3 5 6 + *'); //33 solveRPN('2 3 ^'); // 8
solveRPN('2 4 / 5 6 - *'); //-0.5
solveRPN('2 3 ^'); //8
solveRPN('2 3 ^'); //8
``` ```
</details> </details>
@ -3685,7 +3650,6 @@ const hasFlags = (...flags) =>
```js ```js
// node myScript.js -s --test --cool=true // node myScript.js -s --test --cool=true
hasFlags('-s'); // true hasFlags('-s'); // true
hasFlags('test', 'cool=true'); // true
hasFlags('--test', 'cool=true', '-s'); // true hasFlags('--test', 'cool=true', '-s'); // true
hasFlags('special'); // false hasFlags('special'); // false
``` ```
@ -3984,14 +3948,9 @@ const orderBy = (arr, props, orders) =>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
const users = [ const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
{ name: 'fred', age: 48 }, orderBy(users, ['name', 'age'], ['asc', 'desc']); // [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]
{ name: 'barney', age: 36 }, orderBy(users, ['name', 'age']); // [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]
{ name: 'fred', age: 40 },
{ name: 'barney', age: 34 }
];
orderBy(users, ['name', 'age'], ['asc', 'desc']); // [{name: 'barney', age: 36}, {name: 'barney', age: 34}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]
orderBy(users, ['name', 'age']); // [{name: 'barney', age: 34}, {name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]
``` ```
</details> </details>
@ -4038,8 +3997,7 @@ const shallowClone = obj => Object.assign({}, obj);
```js ```js
const a = { x: true, y: 1 }; const a = { x: true, y: 1 };
const b = shallowClone(a); const b = shallowClone(a); // a !== b
a === b; // false
``` ```
</details> </details>
@ -4087,7 +4045,7 @@ 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. Use `Array.every()` to check if each passed object has the specified property and if it returns a truthy value.
```js ```js
const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pre]); const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pre]);
``` ```
@ -4346,7 +4304,7 @@ isAbsoluteURL('/foo/bar'); // false
Replaces all but the last `num` of characters with the specified mask character. Replaces all but the last `num` of characters with the specified mask character.
Use `String.slice()` to grab the portion of the characters that need to be masked and use `String.replace()` with a regex to replace every character with the mask character. Use `String.slice()` to grab the portion of the characters that need to be masked and use `String.replace()` with a regex to replace every character with the mask character.
Concatenate the masked characters with the remaining unmasked portion of the string. Concatenate the masked characters with the remaining unmasked portion of the string.
Omit the second argument, `num`, to keep a default of `4` characters unmasked. If `num` is negative, the unmasked characters will be at the start of the string. Omit the second argument, `num`, to keep a default of `4` characters unmasked. If `num` is negative, the unmasked characters will be at the start of the string.
Omit the third argument, `mask`, to use a default character of `'*'` for the mask. Omit the third argument, `mask`, to use a default character of `'*'` for the mask.
@ -4362,7 +4320,6 @@ const mask = (cc, num = 4, mask = '*') =>
```js ```js
mask(1234567890); // '******7890' mask(1234567890); // '******7890'
mask(1234567890, 3); // '*******890' mask(1234567890, 3); // '*******890'
mask(1234567890, 4, '$'); // '$$$$$$7890'
mask(1234567890, -4, '$'); // '1234$$$$$$' mask(1234567890, -4, '$'); // '1234$$$$$$'
``` ```
@ -4425,7 +4382,6 @@ const pluralize = (val, word, plural = word + 's') => {
pluralize(0, 'apple'); // 'apples' pluralize(0, 'apple'); // 'apples'
pluralize(1, 'apple'); // 'apple' pluralize(1, 'apple'); // 'apple'
pluralize(2, 'apple'); // 'apples' pluralize(2, 'apple'); // 'apples'
pluralize(1, 'person'); // 'person'
pluralize(2, 'person', 'people'); // 'people' pluralize(2, 'person', 'people'); // 'people'
const PLURALS = { const PLURALS = {
@ -4629,7 +4585,6 @@ const toSnakeCase = str =>
```js ```js
toSnakeCase('camelCase'); // 'camel_case' toSnakeCase('camelCase'); // 'camel_case'
toSnakeCase('some text'); // 'some_text' 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' toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some_mixed_string_with_spaces_underscores_and_hyphens'
toSnakeCase('AllThe-small Things'); // "all_the_smal_things" toSnakeCase('AllThe-small Things'); // "all_the_smal_things"
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html" toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html"
@ -4684,6 +4639,7 @@ const unescapeHTML = str =>
}[tag] || tag) }[tag] || tag)
); );
``` ```
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
@ -4834,7 +4790,7 @@ const getType = v =>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
getType(new Set([1, 2, 3])); // "set" getType(new Set([1, 2, 3])); // 'Set'
``` ```
</details> </details>
@ -5014,7 +4970,7 @@ isFunction(x => x); // true
Returns `true` if the specified value is `null`, `false` otherwise. Returns `true` if the specified value is `null`, `false` otherwise.
Use the strict equality operator to check if the value and of `val` are equal to `null`. Use the strict equality operator to check if the value and of `val` are equal to `null`.
```js ```js
const isNull = val => val === null; const isNull = val => val === null;
@ -5025,7 +4981,6 @@ const isNull = val => val === null;
```js ```js
isNull(null); // true isNull(null); // true
isNull('null'); // false
``` ```
</details> </details>
@ -5050,6 +5005,7 @@ const isNumber = val => typeof val === 'number';
isNumber('1'); // false isNumber('1'); // false
isNumber(1); // true isNumber(1); // true
``` ```
</details> </details>
<br>[⬆ Back to top](#table-of-contents) <br>[⬆ Back to top](#table-of-contents)
@ -5071,14 +5027,12 @@ const isPrimitive = val => !['object', 'function'].includes(typeof val) || val =
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
isPrimitive(window.someNonExistentProperty); // true
isPrimitive(null); // true isPrimitive(null); // true
isPrimitive(50); // true isPrimitive(50); // true
isPrimitive('Hello!'); // true isPrimitive('Hello!'); // true
isPrimitive(false); // true isPrimitive(false); // true
isPrimitive(Symbol()); // true isPrimitive(Symbol()); // true
isPrimitive([]); // false isPrimitive([]); // false
isPrimitive(new String('Hello!')); // false
``` ```
</details> </details>
@ -5131,7 +5085,6 @@ const isString = val => typeof val === 'string';
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
isString(10); // false
isString('10'); // true isString('10'); // true
``` ```
@ -5154,7 +5107,6 @@ const isSymbol = val => typeof val === 'symbol';
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
isSymbol('x'); // false
isSymbol(Symbol('x')); // true isSymbol(Symbol('x')); // true
``` ```
@ -5198,8 +5150,8 @@ isValidJSON(null); // true
Converts a number in bytes to a human-readable string. Converts a number in bytes to a human-readable string.
Use an array dictionary of units to be accessed based on the exponent. Use an array dictionary of units to be accessed based on the exponent.
Use `Number.toPrecision()` to truncate the number to a certain number of digits. Use `Number.toPrecision()` to truncate the number to a certain number of digits.
Return the prettified string by building it up, taking into account the supplied options and whether it is negative or not. Return the prettified string by building it up, taking into account the supplied options and whether it is negative or not.
Omit the second argument, `precision`, to use a default precision of `3` digits. Omit the second argument, `precision`, to use a default precision of `3` digits.
Omit the third argument, `addSpace`, to add space between the number and unit by default. Omit the third argument, `addSpace`, to add space between the number and unit by default.
@ -5219,11 +5171,8 @@ const prettyBytes = (num, precision = 3, addSpace = true) => {
```js ```js
prettyBytes(1000); // 1 KB prettyBytes(1000); // 1 KB
prettyBytes(123456789); // 123 MB prettyBytes(-27145424323.5821, 5); // -27.145 GB
prettyBytes(-50); // -50 B prettyBytes(123456789, 3, false); // 123MB
prettyBytes(27145424323.5821); // 27.1 GB
prettyBytes(27145424323.5821, 5); // 27.145 GB
prettyBytes(5500, 3, false); // 5.5KB
``` ```
</details> </details>
@ -5249,8 +5198,6 @@ const randomHexColorCode = () => {
```js ```js
randomHexColorCode(); // "#e34155" randomHexColorCode(); // "#e34155"
randomHexColorCode(); // "#fd73a6"
randomHexColorCode(); // "#4144c6"
``` ```
</details> </details>
@ -5302,7 +5249,6 @@ const sdbm = str => {
```js ```js
console.log(sdbm('name')); // -3521204949 console.log(sdbm('name')); // -3521204949
console.log(sdbm('age')); // 808122783
``` ```
</details> </details>
@ -5329,8 +5275,7 @@ const timeTaken = callback => {
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
timeTaken(() => Math.pow(2, 10)); // 1024 timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms
// (logged): timeTaken: 0.02099609375ms
``` ```
</details> </details>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,11 +19,7 @@ const orderBy = (arr, props, orders) =>
``` ```
```js ```js
const users = [ const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
{ name: 'fred', age: 48 },
{ name: 'barney', age: 36 },
{ name: 'fred', age: 40 }
];
orderBy(users, ['name', 'age'], ['asc', 'desc']); // [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}] orderBy(users, ['name', 'age'], ['asc', 'desc']); // [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]
orderBy(users, ['name', 'age']); // [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}] orderBy(users, ['name', 'age']); // [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]
``` ```