Travis build: 1507

This commit is contained in:
30secondsofcode
2019-10-15 12:55:58 +00:00
parent 3c2feceebd
commit 150f07d6b8
14 changed files with 204 additions and 98 deletions

View File

@ -384,6 +384,7 @@ _30s.average(1, 2, 3);
* [`forOwnRight`](#forownright)
* [`functions`](#functions)
* [`get`](#get)
* [`hasKey`](#haskey)
* [`invertKeyValues`](#invertkeyvalues)
* [`lowercaseKeys`](#lowercasekeys)
* [`mapKeys`](#mapkeys)
@ -7114,6 +7115,43 @@ get(obj, 'selector.to.val', 'target[0]', 'target[2].a'); // ['val to select', 1,
<br>[⬆ Back to top](#contents)
### hasKey
Returns `true` if the target value exists in a JSON object, `false` otherwise.
Check if the key contains `.`, use `String.prototype.split('.')[0]` to get the first part and store as `_key`.
Use `typeof` to check if the contents of `obj[key]` are an `object` and, if so, call `hasKey` with that object and the remainder of the `key`.
Otherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes()` to check if the given `key` exists.
```js
const hasKey = (obj, key) => {
if (key.includes('.')) {
let _key = key.split('.')[0];
if (typeof obj[_key] === 'object')
return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));
}
return Object.keys(obj).includes(key);
};
```
<details>
<summary>Examples</summary>
```js
let obj = {
a: 1, b: { c: 4 }, 'd.e': 5
};
hasKey(obj, 'a'); // true
hasKey(obj, 'b'); // true
hasKey(obj, 'b.c'); // true
hasKey(obj, 'd.e'); // true
hasKey(obj, 'd'); // false
hasKey(obj, 'f'); // false
```
</details>
<br>[⬆ Back to top](#contents)
### invertKeyValues
Inverts the key-value pairs of an object, without mutating it. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. If a function is supplied, it is applied to each inverted key.

View File

@ -412,7 +412,7 @@
]
},
"meta": {
"hash": "fcf035602ad8241fd8376272afe06f9cb1ab0de65a13b11d46092cacac270a7e"
"hash": "286cf039584d2a4ea54df6456bacb75e28f4fdc0891b61ee94f8ba8266918494"
}
},
{
@ -835,7 +835,7 @@
]
},
"meta": {
"hash": "0a4684d6fc79bdbbac31df3af6c493ba7c881936ada5bc52824b4f26ca177459"
"hash": "5ab25ab96afd4f1f481fc318b5b290ba8c57a468ef6bca0ca200cfb7fcf3ba9f"
}
},
{
@ -898,7 +898,7 @@
]
},
"meta": {
"hash": "a4e1e33c0688dbf1ca231d9d8ea315ffed93b7f83f5d8cbf0714f10fdfeda8cf"
"hash": "7a228b650ff668f697e524e0d27ebeff1bfa35e04333b6cd5e742ff63bfea25d"
}
},
{
@ -1037,7 +1037,7 @@
]
},
"meta": {
"hash": "484bd222e636e8a8409c30ddb1fe6e3fe72ab7a43f2edf089b2758d5e9bee528"
"hash": "5f38360819f9225b887a94221bfee1a80f1bcc224a364440b3388f60491b03ba"
}
},
{
@ -1273,7 +1273,7 @@
]
},
"meta": {
"hash": "0eac852db7a7add352b0d36677b22718b342ed9dc12f11780cac87e3b8260a05"
"hash": "55b1ce0a892110d792a9487e40331774015525479faa2b8961f6c2ea6291c27b"
}
},
{
@ -1678,7 +1678,7 @@
]
},
"meta": {
"hash": "9e39c6a3a8ec5b51c5e16f69107fc9e90b2697b2cf2689850872071bb968723e"
"hash": "16c3b724b653dcb31f3e59f1664a59951abb15a93eb3697cade4d3ae0e63c532"
}
},
{
@ -1842,6 +1842,22 @@
"hash": "e7b6164cfaacf4869f997747df3e135a1ec4342abf5a56498586513332272a96"
}
},
{
"id": "hasKey",
"type": "snippetListing",
"title": "hasKey",
"attributes": {
"text": "Returns `true` if the target value exists in a JSON object, `false` otherwise.\n\nCheck if the key contains `.`, use `String.prototype.split('.')[0]` to get the first part and store as `_key`.\nUse `typeof` to check if the contents of `obj[key]` are an `object` and, if so, call `hasKey` with that object and the remainder of the `key`.\nOtherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes()` to check if the given `key` exists.\n\n",
"tags": [
"object",
"recursion",
"intermediate"
]
},
"meta": {
"hash": "2d4e7ba65fd20501367a46132962fe282099ca6732fdd206204a540f643ce34f"
}
},
{
"id": "head",
"type": "snippetListing",
@ -2820,7 +2836,7 @@
]
},
"meta": {
"hash": "3db3faac666ee61ab86c70766d2ab5d1293ffd818da87edb971bfff7a366364a"
"hash": "362fddaa6244404741e84bca6fc442a101fdb642af53b299e8b9994d0d7162d8"
}
},
{
@ -3713,7 +3729,7 @@
]
},
"meta": {
"hash": "17bcf3f13980b7f804d9f0fe274324b2a35ab7d479c03d77322dabba81e1a34a"
"hash": "7ccbf66d8d55c60bcf12baa980cf32d67a4ba567894d59e2d798c9af792424ff"
}
},
{

View File

@ -568,7 +568,7 @@
]
},
"meta": {
"hash": "fcf035602ad8241fd8376272afe06f9cb1ab0de65a13b11d46092cacac270a7e"
"hash": "286cf039584d2a4ea54df6456bacb75e28f4fdc0891b61ee94f8ba8266918494"
}
},
{
@ -1153,7 +1153,7 @@
]
},
"meta": {
"hash": "0a4684d6fc79bdbbac31df3af6c493ba7c881936ada5bc52824b4f26ca177459"
"hash": "5ab25ab96afd4f1f481fc318b5b290ba8c57a468ef6bca0ca200cfb7fcf3ba9f"
}
},
{
@ -1240,7 +1240,7 @@
]
},
"meta": {
"hash": "a4e1e33c0688dbf1ca231d9d8ea315ffed93b7f83f5d8cbf0714f10fdfeda8cf"
"hash": "7a228b650ff668f697e524e0d27ebeff1bfa35e04333b6cd5e742ff63bfea25d"
}
},
{
@ -1433,7 +1433,7 @@
]
},
"meta": {
"hash": "484bd222e636e8a8409c30ddb1fe6e3fe72ab7a43f2edf089b2758d5e9bee528"
"hash": "5f38360819f9225b887a94221bfee1a80f1bcc224a364440b3388f60491b03ba"
}
},
{
@ -1759,7 +1759,7 @@
]
},
"meta": {
"hash": "0eac852db7a7add352b0d36677b22718b342ed9dc12f11780cac87e3b8260a05"
"hash": "55b1ce0a892110d792a9487e40331774015525479faa2b8961f6c2ea6291c27b"
}
},
{
@ -2320,7 +2320,7 @@
]
},
"meta": {
"hash": "9e39c6a3a8ec5b51c5e16f69107fc9e90b2697b2cf2689850872071bb968723e"
"hash": "16c3b724b653dcb31f3e59f1664a59951abb15a93eb3697cade4d3ae0e63c532"
}
},
{
@ -2544,6 +2544,28 @@
"hash": "e7b6164cfaacf4869f997747df3e135a1ec4342abf5a56498586513332272a96"
}
},
{
"id": "hasKey",
"title": "hasKey",
"type": "snippet",
"attributes": {
"fileName": "hasKey.md",
"text": "Returns `true` if the target value exists in a JSON object, `false` otherwise.\n\nCheck if the key contains `.`, use `String.prototype.split('.')[0]` to get the first part and store as `_key`.\nUse `typeof` to check if the contents of `obj[key]` are an `object` and, if so, call `hasKey` with that object and the remainder of the `key`.\nOtherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes()` to check if the given `key` exists.\n\n",
"codeBlocks": {
"es6": "const hasKey = (obj, key) => {\n if (key.includes('.')) {\n let _key = key.split('.')[0];\n if (typeof obj[_key] === 'object')\n return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));\n }\n return Object.keys(obj).includes(key);\n};",
"es5": "function _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar hasKey = function hasKey(obj, key) {\n if (key.includes('.')) {\n var _key = key.split('.')[0];\n if (_typeof(obj[_key]) === 'object') return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));\n }\n\n return Object.keys(obj).includes(key);\n};",
"example": "let obj = {\n a: 1, b: { c: 4 }, 'd.e': 5\n};\nhasKey(obj, 'a'); // true\nhasKey(obj, 'b'); // true\nhasKey(obj, 'b.c'); // true\nhasKey(obj, 'd.e'); // true\nhasKey(obj, 'd'); // false\nhasKey(obj, 'f'); // false"
},
"tags": [
"object",
"recursion",
"intermediate"
]
},
"meta": {
"hash": "2d4e7ba65fd20501367a46132962fe282099ca6732fdd206204a540f643ce34f"
}
},
{
"id": "head",
"title": "head",
@ -3894,7 +3916,7 @@
]
},
"meta": {
"hash": "3db3faac666ee61ab86c70766d2ab5d1293ffd818da87edb971bfff7a366364a"
"hash": "362fddaa6244404741e84bca6fc442a101fdb642af53b299e8b9994d0d7162d8"
}
},
{
@ -5123,7 +5145,7 @@
]
},
"meta": {
"hash": "17bcf3f13980b7f804d9f0fe274324b2a35ab7d479c03d77322dabba81e1a34a"
"hash": "7ccbf66d8d55c60bcf12baa980cf32d67a4ba567894d59e2d798c9af792424ff"
}
},
{

View File

@ -32,6 +32,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
const lengthIs4 = checkProp(l => l === 4, 'length');

View File

@ -11,6 +11,7 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th
Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
```js
const deepClone = obj => {
if (obj === null) return null;
let clone = Object.assign({}, obj);

View File

@ -10,6 +10,7 @@ Use `Object.keys(obj)` to iterate over the object's keys.
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
```js
const deepMapKeys = (obj, f) =>
Array.isArray(obj)
? obj.map(val => deepMapKeys(val, f))

View File

@ -9,6 +9,7 @@ Use the `in` operator to check if `target` exists in `obj`.
If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
```js
const dig = (obj, target) =>
target in obj
? obj[target]

View File

@ -11,6 +11,7 @@ Otherwise, return the product of `n` and the factorial of `n - 1`.
Throws an exception if `n` is a negative number.
```js
const factorial = n =>
n < 0
? (() => {

View File

@ -8,6 +8,7 @@ Converts an integer to a suffixed string, adding `am` or `pm` based on its value
Use the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
```js
const getMeridiemSuffixOfInteger = num =>
num === 0 || num === 24
? 12 + 'am'

View File

@ -10,20 +10,22 @@ Use `typeof` to check if the contents of `obj[key]` are an `object` and, if so,
Otherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes()` to check if the given `key` exists.
```js
const hasKey = (obj, key) => {
if (key.includes('.')) {
let _key = key.split('.')[0];
if (typeof obj[_key] === 'object')
return hasKey(obj[_key], key.slice(key.indexOf('.') + 1))
return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));
}
return Object.keys(obj).includes(key);
}
};
```
```js
let obj = {
a: 1, b: { c: 4 }, 'd.e': 5
}
};
hasKey(obj, 'a'); // true
hasKey(obj, 'b'); // true
hasKey(obj, 'b.c'); // true

View File

@ -11,6 +11,7 @@ Omit the second argument, `separator`, to use a default separator of `','`.
Omit the third argument, `end`, to use the same value as `separator` by default.
```js
const join = (arr, separator = ',', end = separator) =>
arr.reduce(
(acc, val, i) =>

View File

@ -14,7 +14,6 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr
```
```js
const sum = pipeAsyncFunctions(
x => x + 1,
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),

View File

@ -466,6 +466,14 @@ const hashNode = val =>
0
)
);
const hasKey = (obj, key) => {
if (key.includes('.')) {
let _key = key.split('.')[0];
if (typeof obj[_key] === 'object')
return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));
}
return Object.keys(obj).includes(key);
};
const head = arr => arr[0];
const hexToRGB = hex => {
let alpha = false,
@ -1545,4 +1553,4 @@ const speechSynthesis = message => {
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
module.exports = {all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,checkProp,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compactWhitespace,compose,composeRight,converge,copyToClipboard,countBy,counter,countOccurrences,createDirIfNotExists,createElement,createEventHub,CSVToArray,CSVToJSON,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,deepGet,deepMapKeys,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterFalsy,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,formatDuration,formToObject,forOwn,forOwnRight,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,inRange,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNegativeZero,isNil,isNull,isNumber,isObject,isObjectLike,isOdd,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWeekday,isWeekend,isWritableStream,join,JSONtoCSV,JSONToFile,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapNumRange,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,midpoint,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,once,onUserInputChange,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reducedFilter,reduceSuccessive,reduceWhich,reject,remove,removeNonASCII,renameKeys,reverseString,RGBToHex,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,serializeForm,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,times,timeTaken,toCamelCase,toCurrency,toDecimalMark,toggleClass,toHash,toKebabCase,tomorrow,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,validateNumber,vectorDistance,when,without,words,xProd,yesNo,yesterday,zip,zipObject,zipWith,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,JSONToDate,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
module.exports = {all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,checkProp,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compactWhitespace,compose,composeRight,converge,copyToClipboard,countBy,counter,countOccurrences,createDirIfNotExists,createElement,createEventHub,CSVToArray,CSVToJSON,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,deepGet,deepMapKeys,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterFalsy,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,formatDuration,formToObject,forOwn,forOwnRight,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,hasKey,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,inRange,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNegativeZero,isNil,isNull,isNumber,isObject,isObjectLike,isOdd,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWeekday,isWeekend,isWritableStream,join,JSONtoCSV,JSONToFile,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapNumRange,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,midpoint,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,once,onUserInputChange,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reducedFilter,reduceSuccessive,reduceWhich,reject,remove,removeNonASCII,renameKeys,reverseString,RGBToHex,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,serializeForm,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,times,timeTaken,toCamelCase,toCurrency,toDecimalMark,toggleClass,toHash,toKebabCase,tomorrow,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,validateNumber,vectorDistance,when,without,words,xProd,yesNo,yesterday,zip,zipObject,zipWith,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,JSONToDate,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}

View File

@ -1166,6 +1166,20 @@
],
"description": "Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.\n\nUse `crypto` API to create a hash for the given value, `setTimeout` to prevent blocking on a long operation, and a `Promise` to give it a familiar interface.\n"
},
"hasKey": {
"prefix": "30s_hasKey",
"body": [
"const hasKey = (obj, key) => {",
" if (key.includes('.')) {",
" let _key = key.split('.')[0];",
" if (typeof obj[_key] === 'object')",
" return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));",
" }",
" return Object.keys(obj).includes(key);",
"};"
],
"description": "Returns `true` if the target value exists in a JSON object, `false` otherwise.\n\nCheck if the key contains `.`, use `String.prototype.split('.')[0]` to get the first part and store as `_key`.\nUse `typeof` to check if the contents of `obj[key]` are an `object` and, if so, call `hasKey` with that object and the remainder of the `key`.\nOtherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes()` to check if the given `key` exists.\n"
},
"head": {
"prefix": "30s_head",
"body": [