Files
30-seconds-of-code/snippet_data/archivedSnippetList.json
2019-08-13 14:22:41 +03:00

386 lines
16 KiB
JSON

{
"data": [
{
"id": "binarySearch",
"type": "snippetListing",
"title": "binarySearch",
"attributes": {
"text": "Use recursion. Similar to `Array.prototype.indexOf()` that finds the index of a value within an array.\nThe difference being this operation only works with sorted arrays which offers a major performance boost due to it's logarithmic nature when compared to a linear search or `Array.prototype.indexOf()`.\n\nSearch a sorted array by repeatedly dividing the search interval in half.\nBegin with an interval covering the whole array.\nIf the value of the search is less than the item in the middle of the interval, recurse into the lower half. Otherwise recurse into the upper half.\nRepeatedly recurse until the value is found which is the mid or you've recursed to a point that is greater than the length which means the value doesn't exist and return `-1`.\n\n",
"tags": [
"algorithm",
"beginner"
]
},
"meta": {
"hash": "48d538bccbc7be7e78b8f6a69004055c4b21324d2c8d7cbc4cba0cd42e4f67fb"
}
},
{
"id": "celsiusToFahrenheit",
"type": "snippetListing",
"title": "celsiusToFahrenheit",
"attributes": {
"text": "Celsius to Fahrenheit temperature conversion.\n\nFollows the conversion formula `F = 1.8C + 32`.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "d59410c4fa0ea5173af553068c1e1d4ef931695e084c50cdd8166b0cd0278722"
}
},
{
"id": "cleanObj",
"type": "snippetListing",
"title": "cleanObj",
"attributes": {
"text": "Removes any properties except the ones specified from a JSON object.\n\nUse `Object.keys()` method to loop over given JSON object and deleting keys that are not included in given array.\nIf you pass a special key,`childIndicator`, it will search deeply apply the function to inner objects, too.\n\n",
"tags": [
"object",
"beginner"
]
},
"meta": {
"hash": "aaefc9bd6e9170001fe4754b1bc7bb9808ab97a5bec7fc6ceb1193be2f8009b1"
}
},
{
"id": "collatz",
"type": "snippetListing",
"title": "collatz",
"attributes": {
"text": "Applies the Collatz algorithm.\n\nIf `n` is even, return `n/2`. Otherwise, return `3n+1`.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "0280a47e49f505d5f10e0e0bd2c3ab28a6ea2b931fc83f63155f8395f64a1840"
}
},
{
"id": "countVowels",
"type": "snippetListing",
"title": "countVowels",
"attributes": {
"text": "Retuns `number` of vowels in provided string.\n\nUse a regular expression to count the number of vowels `(A, E, I, O, U)` in a `string`.\n\n",
"tags": [
"string",
"beginner"
]
},
"meta": {
"hash": "961b406dfe98746e3a267532b0703ee7c5c1b1c01a0e04c1f9e13e0fd0aeced1"
}
},
{
"id": "factors",
"type": "snippetListing",
"title": "factors",
"attributes": {
"text": "Returns the array of factors of the given `num`.\nIf the second argument is set to `true` returns only the prime factors of `num`.\nIf `num` is `1` or `0` returns an empty array.\nIf `num` is less than `0` returns all the factors of `-int` together with their additive inverses.\n\nUse `Array.from()`, `Array.prototype.map()` and `Array.prototype.filter()` to find all the factors of `num`.\nIf given `num` is negative, use `Array.prototype.reduce()` to add the additive inverses to the array.\nReturn all results if `primes` is `false`, else determine and return only the prime factors using `isPrime` and `Array.prototype.filter()`.\nOmit the second argument, `primes`, to return prime and non-prime factors by default.\n\n**Note**:- _Negative numbers are not considered prime._\n\n",
"tags": [
"math",
"intermediate"
]
},
"meta": {
"hash": "8eed39b1040d6472e2fd619abf744848d30f12eebffda2711966c616d474524f"
}
},
{
"id": "fahrenheitToCelsius",
"type": "snippetListing",
"title": "fahrenheitToCelsius",
"attributes": {
"text": "Fahrenheit to Celsius temperature conversion.\n\nFollows the conversion formula `C = (F - 32) * 5/9`.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "a39ade2ae05ad86443446b335dbc019e3ac734fe0c1a542d50b929c554040fc0"
}
},
{
"id": "fibonacciCountUntilNum",
"type": "snippetListing",
"title": "fibonacciCountUntilNum",
"attributes": {
"text": "Returns the number of fibonnacci numbers up to `num`(`0` and `num` inclusive).\n\nUse a mathematical formula to calculate the number of fibonacci numbers until `num`.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "35488eb0f56b59035b56cc67fa0a5e1a970162ede4aafd97ebb2b4009c321c01"
}
},
{
"id": "fibonacciUntilNum",
"type": "snippetListing",
"title": "fibonacciUntilNum",
"attributes": {
"text": "Generates an array, containing the Fibonacci sequence, up until the nth term.\n\nCreate an empty array of the specific length, initializing the first two values (`0` and `1`).\nUse `Array.prototype.reduce()` to add values into the array, using the sum of the last two values, except for the first two.\nUses a mathematical formula to calculate the length of the array required.\n\n",
"tags": [
"math",
"intermediate"
]
},
"meta": {
"hash": "6ff845c13444a06569be548ce9e69900b7001516c44c315795f34b31e9baa833"
}
},
{
"id": "heronArea",
"type": "snippetListing",
"title": "heronArea",
"attributes": {
"text": "Returns the area of a triangle using only the 3 side lengths, Heron's formula. Assumes that the sides define a valid triangle. Does NOT assume it is a right triangle.\n\nMore information on what Heron's formula is and why it works available here: https://en.wikipedia.org/wiki/Heron%27s_formula.\n\nUses `Math.sqrt()` to find the square root of a value.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "d0be594ab377cbeb2910308610af5890b3468c06e7567cd0995a84d11aaccf47"
}
},
{
"id": "howManyTimes",
"type": "snippetListing",
"title": "howManyTimes",
"attributes": {
"text": "Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer.\nWorks for both negative and positive integers.\n\nIf `divisor` is `-1` or `1` return `Infinity`.\nIf `divisor` is `-0` or `0` return `0`.\nOtherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer.\nReturn the number of times the loop was executed, `i`.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "52ffa251dfc4e2bec7160a9066ef24a8c3047706e1ad2837f9d987cdf4d5f73e"
}
},
{
"id": "httpDelete",
"type": "snippetListing",
"title": "httpDelete",
"attributes": {
"text": "Makes a `DELETE` request to the passed URL.\n\nUse `XMLHttpRequest` web api to make a `delete` request to the given `url`.\nHandle the `onload` event, by running the provided `callback` function.\nHandle the `onerror` event, by running the provided `err` function.\nOmit the third argument, `err` to log the request to the console's error stream by default.\n\n",
"tags": [
"browser",
"intermediate"
]
},
"meta": {
"hash": "4fccb2abe966313a742d13965ee46cfd1094763a2697591eddb19c1c5af1db7e"
}
},
{
"id": "httpPut",
"type": "snippetListing",
"title": "httpPut",
"attributes": {
"text": "Makes a `PUT` request to the passed URL.\n\nUse `XMLHttpRequest` web api to make a `put` request to the given `url`.\nSet the value of an `HTTP` request header with `setRequestHeader` method.\nHandle the `onload` event, by running the provided `callback` function.\nHandle the `onerror` event, by running the provided `err` function.\nOmit the last argument, `err` to log the request to the console's error stream by default.\n\n",
"tags": [
"browser",
"intermediate"
]
},
"meta": {
"hash": "7eb4b1ffc1cbe28c10190bb82b7731ade2d79e78a5569bdee62af33a1020f2f5"
}
},
{
"id": "isArmstrongNumber",
"type": "snippetListing",
"title": "isArmstrongNumber",
"attributes": {
"text": "Checks if the given number is an Armstrong number or not.\n\nConvert the given number into an array of digits. Use the exponent operator (`**`) 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`.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "71ebcdb61794d8222fcf447509d206ffb10dc8068072a88c6b587e21e76fc7f2"
}
},
{
"id": "isSimilar",
"type": "snippetListing",
"title": "isSimilar",
"attributes": {
"text": "Determines if the `pattern` matches with `str`.\n\nUse `String.toLowerCase()` to convert both strings to lowercase, then loop through `str` and determine if it contains all characters of `pattern` and in the correct order.\nAdapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db53428247e741b9efe2cde9667050c/code/fts_fuzzy_match.js#L18).\n\n",
"tags": [
"string",
"intermediate"
]
},
"meta": {
"hash": "250615cfc281e99014b97d054c722d3ba6aa4190ccf66dd719e530ec80aec3bd"
}
},
{
"id": "JSONToDate",
"type": "snippetListing",
"title": "JSONToDate",
"attributes": {
"text": "Converts a JSON object to a date.\n\nUse `Date()`, to convert dates in JSON format to readable format (`dd/mm/yyyy`).\n\n",
"tags": [
"object",
"date",
"beginner"
]
},
"meta": {
"hash": "33e1e304fead4088971a60d4da974d0e9380370560f383ddb1ddc14e628df18b"
}
},
{
"id": "kmphToMph",
"type": "snippetListing",
"title": "kmphToMph",
"attributes": {
"text": "Convert kilometers/hour to miles/hour.\n\nMultiply the constant of proportionality with the argument.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "f885a599e1185f8480445e1eb0c4a5cb8bf33948d7893f013dd4e8085478fe7a"
}
},
{
"id": "levenshteinDistance",
"type": "snippetListing",
"title": "levenshteinDistance",
"attributes": {
"text": "Calculates the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings.\n\nCalculates the number of changes (substitutions, deletions or additions) required to convert `string1` to `string2`. \nCan also be used to compare two strings as shown in the second example.\n\n",
"tags": [
"algorithm",
"advanced"
]
},
"meta": {
"hash": "9f71509c5937cb68b65ef31893b1ad723ce6690e8ecd161707cb222ab67a475b"
}
},
{
"id": "mphToKmph",
"type": "snippetListing",
"title": "mphToKmph",
"attributes": {
"text": "Convert miles/hour to kilometers/hour.\n\nMultiply the constant of proportionality with the argument.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "d1ec7968c8f8c48642a3f91878db84330231bdf84bf74633dc0754456e951338"
}
},
{
"id": "pipeLog",
"type": "snippetListing",
"title": "pipeLog",
"attributes": {
"text": "Logs a value and returns it.\n\nUse `console.log` to log the supplied value, combined with the `||` operator to return it.\n\n",
"tags": [
"utility",
"beginner"
]
},
"meta": {
"hash": "dba6fa36424c23d601c4e463463a5f23d32b51d8b058a6c5020d3b4098a65e51"
}
},
{
"id": "quickSort",
"type": "snippetListing",
"title": "quickSort",
"attributes": {
"text": "QuickSort an Array (ascending sort by default).\n\nUse recursion.\nUse `Array.prototype.filter` and spread operator (`...`) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it.\nIf the parameter `desc` is truthy, return array sorts in descending order.\n\n",
"tags": [
"algorithm",
"recursion",
"beginner"
]
},
"meta": {
"hash": "5c26069a02342eadd2c5ba2656a1b211da8f1a94da03c2cc31a5090be556d7b7"
}
},
{
"id": "removeVowels",
"type": "snippetListing",
"title": "removeVowels",
"attributes": {
"text": "Returns all the vowels in a `str` replaced by `repl`.\n\nUse `String.prototype.replace()` with a regexp to replace all vowels in `str`.\nOmot `repl` to use a default value of `''`.\n\n",
"tags": [
"string",
"beginner"
]
},
"meta": {
"hash": "5c6f8e292db8506568de362aa63890047f9d5a65d35143cfca1e27562642c414"
}
},
{
"id": "solveRPN",
"type": "snippetListing",
"title": "solveRPN",
"attributes": {
"text": "Solves the given mathematical expression in [reverse polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation).\nThrows appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :- `+`,`-`,`*`,`/`,`^`,`**` (`^`&`**` are the exponential symbols and are same). This snippet does not supports any unary operators.\n\nUse a dictionary, `OPERATORS` to specify each operator's matching mathematical operation.\nUse `String.prototype.replace()` with a regular expression to replace `^` with `**`, `String.prototype.split()` to tokenize the string and `Array.prototype.filter()` to remove empty tokens.\nUse `Array.prototype.forEach()` to parse each `symbol`, evaluate it as a numeric value or operator and solve the mathematical expression.\nNumeric values are converted to floating point numbers and pushed to a `stack`, while operators are evaluated using the `OPERATORS` dictionary and pop elements from the `stack` to apply operations.\n\n",
"tags": [
"algorithm",
"advanced"
]
},
"meta": {
"hash": "0c37cf46586652fd20dfa9ca682d3635f01fe61c46864f9773f6b258e8f3b6f6"
}
},
{
"id": "speechSynthesis",
"type": "snippetListing",
"title": "speechSynthesis",
"attributes": {
"text": "Performs speech synthesis (experimental).\n\nUse `SpeechSynthesisUtterance.voice` and `window.speechSynthesis.getVoices()` to convert a message to speech.\nUse `window.speechSynthesis.speak()` to play the message.\n\nLearn more about the [SpeechSynthesisUtterance interface of the Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance).\n\n",
"tags": [
"browser",
"intermediate"
]
},
"meta": {
"hash": "9859dbef05dc0398e825150b50fccfea370583cf6b807c00c9e83b769d2b51c0"
}
},
{
"id": "squareSum",
"type": "snippetListing",
"title": "squareSum",
"attributes": {
"text": "Squares each number in an array and then sums the results together.\n\nUse `Array.prototype.reduce()` in combination with `Math.pow()` to iterate over numbers and sum their squares into an accumulator.\n\n",
"tags": [
"math",
"beginner"
]
},
"meta": {
"hash": "19837ac6714833e9c5fe698811e171cc2598f7b9405a4847b33b8d3b35debf8a"
}
}
],
"meta": {
"specification": "http://jsonapi.org/format/",
"type": "snippetListingArray",
"scope": "./snippets_archive"
}
}