diff --git a/migrator.js b/migrator.js new file mode 100644 index 000000000..e9244a033 --- /dev/null +++ b/migrator.js @@ -0,0 +1,24 @@ +const snippets = require('./snippet_data/snippets.json'); +const fs = require('fs-extra'); +const path = require('path'); + +snippets.data.forEach(snippet => { + fs.writeFileSync( + path.join( + snippet.meta.archived ? './snippets_archive' : './snippets', + `${snippet.attributes.fileName}`), +`--- +title: ${snippet.id} +tags: ${snippet.attributes.tags.join(',')} +--- + +${snippet.attributes.text} + +\`\`\`js +${snippet.attributes.codeBlocks.es6} +\`\`\` + +\`\`\`js +${snippet.attributes.codeBlocks.example} +\`\`\``); +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fb4e118e1..356d1967e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3488,7 +3488,7 @@ "version": "1.2.5", "bundled": true, "requires": { - "minipass": "2.2.4" + "minipass": "^2.2.1" } }, "fs.realpath": { @@ -3606,17 +3606,16 @@ "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { - "safe-buffer": "5.1.1", - "yallist": "3.0.2" + "safe-buffer": "^5.1.1", + "yallist": "^3.0.0" } }, "minizlib": { "version": "1.1.0", "bundled": true, "requires": { - "minipass": "2.2.4" + "minipass": "^2.2.1" } }, "mkdirp": { @@ -3651,16 +3650,16 @@ "dev": true, "optional": true, "requires": { - "detect-libc": "1.0.3", - "mkdirp": "0.5.1", - "needle": "2.2.0", - "nopt": "4.0.1", - "npm-packlist": "1.1.10", - "npmlog": "4.1.2", - "rc": "1.2.7", - "rimraf": "2.6.2", - "semver": "5.5.0", - "tar": "4.4.1" + "detect-libc": "^1.0.2", + "mkdirp": "^0.5.1", + "needle": "^2.2.0", + "nopt": "^4.0.1", + "npm-packlist": "^1.1.6", + "npmlog": "^4.0.2", + "rc": "^1.1.7", + "rimraf": "^2.6.1", + "semver": "^5.3.0", + "tar": "^4" } }, "nopt": { @@ -3802,8 +3801,7 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -3893,8 +3891,7 @@ }, "yallist": { "version": "3.0.2", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -6049,11 +6046,11 @@ "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" } }, "cross-spawn": { diff --git a/package.json b/package.json index 5b561039c..888eb2836 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,11 @@ "glossary:keymaker": "node ./scripts/glossary/keyword.js", "builder": "node ./scripts/build.js", "linter": "node ./scripts/lint.js", - "tagger": "node ./scripts/tag.js", "webber": "node ./scripts/web.js", "tester": "node ./scripts/tdd.js", "extractor": "node ./scripts/extract.js", "vscoder": "node ./scripts/vscodegen.js", "packager": "node ./scripts/module.js", - "localizer": "node ./scripts/localize.js", "test": "jest --verbose --coverage" }, "repository": { diff --git a/scripts/tag.js b/scripts/tag.js deleted file mode 100644 index 19c66adf6..000000000 --- a/scripts/tag.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - This is the tagger script that updates the tag_databse file and logs stats for snippet tags. - Run using `npm run tagger`. -*/ -// Load modules -const fs = require('fs-extra'), - { black, blue, green, yellow, red, bgWhite } = require('kleur'); -const util = require('./util'); -if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) { - console.log(`${green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`); - process.exit(0); -} -// Set variables for paths -const snippetsPath = './snippets'; -// Set variables for script -let snippets = {}, - output = '', - tagDbData = {}, - missingTags = 0, - tagDbStats = {}; -// Start the timer of the script -console.time('Tagger'); -// Synchronously read all snippets and sort them as necessary (case-insensitive) -snippets = util.readSnippets(snippetsPath); -// Load tag data from the database -tagDbData = util.readTags(); -tagDbStats = Object.entries(tagDbData).reduce((acc, val) => { - val[1].forEach(v => (acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1))); - return acc; -}, {}); -// Update the listing of snippets in tag_database and log the statistics, along with missing scripts -try { - for (let snippet of Object.entries(snippets)) { - if ( - tagDbData.hasOwnProperty(snippet[0].slice(0, -3)) && - tagDbData[snippet[0].slice(0, -3)].join(',').trim() - ) { - output += `${snippet[0].slice(0, -3)}:${tagDbData[snippet[0].slice(0, -3)] - .join(',') - .trim()}\n`; - } else { - output += `${snippet[0].slice(0, -3)}:uncategorized\n`; - missingTags++; - console.log(`${yellow('Tagged uncategorized:')} ${snippet[0].slice(0, -3)}`); - } - } - // Write to tag_database - fs.writeFileSync('tag_database', output); -} catch (err) { - // Handle errors (hopefully not!) - console.log(`${red('ERROR!')} During tag_database generation: ${err}`); - process.exit(1); -} -// Log statistics for the tag_database file -console.log(`\n${bgWhite(black('=== TAG STATS ==='))}`); -for (let tagData of Object.entries(tagDbStats) - .filter(v => v[0] !== 'undefined') - .sort((a, b) => a[0].localeCompare(b[0]))) - console.log(`${green(tagData[0])}: ${tagData[1]} snippets`); -console.log( - `${blue("New untagged snippets (will be tagged as 'uncategorized'):")} ${missingTags}\n` -); -// Log a success message -console.log(`${green('SUCCESS!')} tag_database file updated!`); -// Log the time taken -console.timeEnd('Tagger'); diff --git a/snippets/CSVToArray.md b/snippets/CSVToArray.md index f5322840e..dc448de3d 100644 --- a/snippets/CSVToArray.md +++ b/snippets/CSVToArray.md @@ -1,4 +1,7 @@ -### CSVToArray +--- +title: CSVToArray +tags: string,array,utility,intermediate +--- Converts a comma-separated values (CSV) string to a 2D array. @@ -19,4 +22,4 @@ const CSVToArray = (data, delimiter = ',', omitFirstRow = false) => CSVToArray('a,b\nc,d'); // [['a','b'],['c','d']]; CSVToArray('a;b\nc;d', ';'); // [['a','b'],['c','d']]; CSVToArray('col1,col2\na,b\nc,d', ',', true); // [['a','b'],['c','d']]; -``` +``` \ No newline at end of file diff --git a/snippets/CSVToJSON.md b/snippets/CSVToJSON.md index c2f6e6bb5..0f237885b 100644 --- a/snippets/CSVToJSON.md +++ b/snippets/CSVToJSON.md @@ -1,4 +1,7 @@ -### CSVToJSON +--- +title: CSVToJSON +tags: string,array,object,advanced +--- Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row. @@ -24,4 +27,4 @@ const CSVToJSON = (data, delimiter = ',') => { ```js CSVToJSON('col1,col2\na,b\nc,d'); // [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; CSVToJSON('col1;col2\na;b\nc;d', ';'); // [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; -``` +``` \ No newline at end of file diff --git a/snippets/JSONToFile.md b/snippets/JSONToFile.md index 1327d472b..71f063108 100644 --- a/snippets/JSONToFile.md +++ b/snippets/JSONToFile.md @@ -1,4 +1,7 @@ -### JSONToFile +--- +title: JSONToFile +tags: node,json,intermediate +--- Writes a JSON object to a file. @@ -12,4 +15,4 @@ const JSONToFile = (obj, filename) => ```js JSONToFile({ test: 'is passed' }, 'testJsonFile'); // writes the object to 'testJsonFile.json' -``` +``` \ No newline at end of file diff --git a/snippets/JSONtoCSV.md b/snippets/JSONtoCSV.md index b4d83dd7f..554bda5b2 100644 --- a/snippets/JSONtoCSV.md +++ b/snippets/JSONtoCSV.md @@ -1,4 +1,7 @@ -### JSONtoCSV +--- +title: JSONtoCSV +tags: array,string,object,advanced +--- Converts an array of objects to a comma-separated values (CSV) string that contains only the `columns` specified. @@ -23,4 +26,4 @@ const JSONtoCSV = (arr, columns, delimiter = ',') => ```js JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b']); // 'a,b\n"1","2"\n"3","4"\n"6",""\n"","7"' JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';'); // 'a;b\n"1";"2"\n"3";"4"\n"6";""\n"";"7"' -``` +``` \ No newline at end of file diff --git a/snippets/RGBToHex.md b/snippets/RGBToHex.md index 4b3f6b35f..4d9ea9391 100644 --- a/snippets/RGBToHex.md +++ b/snippets/RGBToHex.md @@ -1,4 +1,7 @@ -### RGBToHex +--- +title: RGBToHex +tags: utility,intermediate +--- Converts the values of RGB components to a color code. @@ -10,4 +13,4 @@ const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6 ```js RGBToHex(255, 165, 1); // 'ffa501' -``` +``` \ No newline at end of file diff --git a/snippets/URLJoin.md b/snippets/URLJoin.md index 3922a173a..a9256f8cf 100644 --- a/snippets/URLJoin.md +++ b/snippets/URLJoin.md @@ -1,4 +1,7 @@ -### URLJoin +--- +title: URLJoin +tags: string,utility,regexp,advanced +--- Joins all given URL segments together, then normalizes the resulting URL. @@ -18,4 +21,4 @@ const URLJoin = (...args) => ```js URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo' -``` +``` \ No newline at end of file diff --git a/snippets/UUIDGeneratorBrowser.md b/snippets/UUIDGeneratorBrowser.md index 3fc752f95..4d11897ef 100644 --- a/snippets/UUIDGeneratorBrowser.md +++ b/snippets/UUIDGeneratorBrowser.md @@ -1,4 +1,7 @@ -### UUIDGeneratorBrowser +--- +title: UUIDGeneratorBrowser +tags: browser,utility,random,intermediate +--- Generates a UUID in a browser. @@ -13,4 +16,4 @@ const UUIDGeneratorBrowser = () => ```js UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d' -``` +``` \ No newline at end of file diff --git a/snippets/UUIDGeneratorNode.md b/snippets/UUIDGeneratorNode.md index bbcb51b8f..4d4a0d085 100644 --- a/snippets/UUIDGeneratorNode.md +++ b/snippets/UUIDGeneratorNode.md @@ -1,4 +1,7 @@ -### UUIDGeneratorNode +--- +title: UUIDGeneratorNode +tags: node,utility,random,intermediate +--- Generates a UUID in Node.JS. @@ -14,4 +17,4 @@ const UUIDGeneratorNode = () => ```js UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' -``` +``` \ No newline at end of file diff --git a/snippets/all.md b/snippets/all.md index 8914d1ff6..850a887cc 100644 --- a/snippets/all.md +++ b/snippets/all.md @@ -1,4 +1,7 @@ -### all +--- +title: all +tags: array,function,beginner +--- Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise. @@ -12,4 +15,4 @@ const all = (arr, fn = Boolean) => arr.every(fn); ```js all([4, 2, 3], x => x > 1); // true all([1, 2, 3]); // true -``` +``` \ No newline at end of file diff --git a/snippets/allEqual.md b/snippets/allEqual.md index 0378f5e79..f275c314e 100644 --- a/snippets/allEqual.md +++ b/snippets/allEqual.md @@ -1,4 +1,7 @@ -### allEqual +--- +title: allEqual +tags: array,function,beginner +--- Check if all elements in an array are equal. @@ -12,4 +15,4 @@ const allEqual = arr => arr.every(val => val === arr[0]); ```js allEqual([1, 2, 3, 4, 5, 6]); // false allEqual([1, 1, 1, 1]); // true -``` +``` \ No newline at end of file diff --git a/snippets/any.md b/snippets/any.md index f8cc90d96..23e8face3 100644 --- a/snippets/any.md +++ b/snippets/any.md @@ -1,4 +1,7 @@ -### any +--- +title: any +tags: array,function,beginner +--- Returns `true` if the provided predicate function returns `true` for at least one element in a collection, `false` otherwise. @@ -12,4 +15,4 @@ const any = (arr, fn = Boolean) => arr.some(fn); ```js any([0, 1, 2, 0], x => x >= 2); // true any([0, 0, 1, 0]); // true -``` +``` \ No newline at end of file diff --git a/snippets/approximatelyEqual.md b/snippets/approximatelyEqual.md index 88773c163..7723f2440 100644 --- a/snippets/approximatelyEqual.md +++ b/snippets/approximatelyEqual.md @@ -1,4 +1,7 @@ -### approximatelyEqual +--- +title: approximatelyEqual +tags: math,beginner +--- Checks if two numbers are approximately equal to each other. @@ -11,4 +14,4 @@ const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsi ```js approximatelyEqual(Math.PI / 2.0, 1.5708); // true -``` +``` \ No newline at end of file diff --git a/snippets/arrayToCSV.md b/snippets/arrayToCSV.md index 727c41f2e..f78ffdbc4 100644 --- a/snippets/arrayToCSV.md +++ b/snippets/arrayToCSV.md @@ -1,4 +1,7 @@ -### arrayToCSV +--- +title: arrayToCSV +tags: array,string,utility,intermediate +--- Converts a 2D array to a comma-separated values (CSV) string. @@ -17,4 +20,4 @@ const arrayToCSV = (arr, delimiter = ',') => arrayToCSV([['a', 'b'], ['c', 'd']]); // '"a","b"\n"c","d"' arrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '"a";"b"\n"c";"d"' arrayToCSV([['a', '"b" great'], ['c', 3.1415]]); // '"a","""b"" great"\n"c",3.1415' -``` +``` \ No newline at end of file diff --git a/snippets/arrayToHtmlList.md b/snippets/arrayToHtmlList.md index 22b61c7b2..1122b9bc0 100644 --- a/snippets/arrayToHtmlList.md +++ b/snippets/arrayToHtmlList.md @@ -1,4 +1,7 @@ -### arrayToHtmlList +--- +title: arrayToHtmlList +tags: browser,array,intermediate +--- Converts the given array elements into `
  • ` tags and appends them to the list of the given id. @@ -14,4 +17,4 @@ const arrayToHtmlList = (arr, listID) => ```js arrayToHtmlList(['item 1', 'item 2'], 'myListID'); -``` +``` \ No newline at end of file diff --git a/snippets/ary.md b/snippets/ary.md index 8eb520526..eb0735111 100644 --- a/snippets/ary.md +++ b/snippets/ary.md @@ -1,4 +1,7 @@ -### ary +--- +title: ary +tags: adapter,function,intermediate +--- Creates a function that accepts up to `n` arguments, ignoring any additional arguments. @@ -11,4 +14,4 @@ const ary = (fn, n) => (...args) => fn(...args.slice(0, n)); ```js const firstTwoMax = ary(Math.max, 2); [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10] -``` +``` \ No newline at end of file diff --git a/snippets/atob.md b/snippets/atob.md index ce01ec1e2..222c052a2 100644 --- a/snippets/atob.md +++ b/snippets/atob.md @@ -1,4 +1,7 @@ -### atob +--- +title: atob +tags: node,string,utility,beginner +--- Decodes a string of data which has been encoded using base-64 encoding. @@ -10,4 +13,4 @@ const atob = str => Buffer.from(str, 'base64').toString('binary'); ```js atob('Zm9vYmFy'); // 'foobar' -``` +``` \ No newline at end of file diff --git a/snippets/attempt.md b/snippets/attempt.md index 4cf9aa9a6..abf860c28 100644 --- a/snippets/attempt.md +++ b/snippets/attempt.md @@ -1,4 +1,7 @@ -### attempt +--- +title: attempt +tags: function,intermediate +--- Attempts to invoke a function with the provided arguments, returning either the result or the caught error object. @@ -19,4 +22,4 @@ var elements = attempt(function(selector) { return document.querySelectorAll(selector); }, '>_>'); if (elements instanceof Error) elements = []; // elements = [] -``` +``` \ No newline at end of file diff --git a/snippets/average.md b/snippets/average.md index 88b92a546..17cec6639 100644 --- a/snippets/average.md +++ b/snippets/average.md @@ -1,4 +1,7 @@ -### average +--- +title: average +tags: math,array,beginner +--- Returns the average of two or more numbers. @@ -11,4 +14,4 @@ const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.leng ```js average(...[1, 2, 3]); // 2 average(1, 2, 3); // 2 -``` +``` \ No newline at end of file diff --git a/snippets/averageBy.md b/snippets/averageBy.md index c3ade444b..726ec3b2c 100644 --- a/snippets/averageBy.md +++ b/snippets/averageBy.md @@ -1,4 +1,7 @@ -### averageBy +--- +title: averageBy +tags: math,array,function,intermediate +--- Returns the average of an array, after mapping each element to a value using the provided function. @@ -13,4 +16,4 @@ const averageBy = (arr, fn) => ```js averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 5 averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5 -``` +``` \ No newline at end of file diff --git a/snippets/bifurcate.md b/snippets/bifurcate.md index 3126e3db0..360cd9344 100644 --- a/snippets/bifurcate.md +++ b/snippets/bifurcate.md @@ -1,4 +1,7 @@ -### bifurcate +--- +title: bifurcate +tags: array,intermediate +--- Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group. @@ -11,4 +14,4 @@ const bifurcate = (arr, filter) => ```js bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ] -``` +``` \ No newline at end of file diff --git a/snippets/bifurcateBy.md b/snippets/bifurcateBy.md index 119d72936..3332a83b5 100644 --- a/snippets/bifurcateBy.md +++ b/snippets/bifurcateBy.md @@ -1,4 +1,7 @@ -### bifurcateBy +--- +title: bifurcateBy +tags: array,function,intermediate +--- Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group. @@ -11,4 +14,4 @@ const bifurcateBy = (arr, fn) => ```js bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ] -``` +``` \ No newline at end of file diff --git a/snippets/bind.md b/snippets/bind.md index 2cc606864..c0785dd61 100644 --- a/snippets/bind.md +++ b/snippets/bind.md @@ -1,4 +1,7 @@ -### bind +--- +title: bind +tags: function,object,intermediate +--- Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments. @@ -16,4 +19,4 @@ function greet(greeting, punctuation) { const freddy = { user: 'fred' }; const freddyBound = bind(greet, freddy); console.log(freddyBound('hi', '!')); // 'hi fred!' -``` +``` \ No newline at end of file diff --git a/snippets/bindAll.md b/snippets/bindAll.md index 656ff6bf7..d64572e41 100644 --- a/snippets/bindAll.md +++ b/snippets/bindAll.md @@ -1,4 +1,7 @@ -### bindAll +--- +title: bindAll +tags: object,function,intermediate +--- Binds methods of an object to the object itself, overwriting the existing method. @@ -25,4 +28,4 @@ var view = { }; bindAll(view, 'click'); jQuery(element).on('click', view.click); // Logs 'clicked docs' when clicked. -``` +``` \ No newline at end of file diff --git a/snippets/bindKey.md b/snippets/bindKey.md index 2c78cfda7..950fffaf9 100644 --- a/snippets/bindKey.md +++ b/snippets/bindKey.md @@ -1,4 +1,7 @@ -### bindKey +--- +title: bindKey +tags: function,object,intermediate +--- Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments. @@ -19,4 +22,4 @@ const freddy = { }; const freddyBound = bindKey(freddy, 'greet'); console.log(freddyBound('hi', '!')); // 'hi fred!' -``` +``` \ No newline at end of file diff --git a/snippets/binomialCoefficient.md b/snippets/binomialCoefficient.md index d5ff87d16..8fc03bcb0 100644 --- a/snippets/binomialCoefficient.md +++ b/snippets/binomialCoefficient.md @@ -1,4 +1,7 @@ -### binomialCoefficient +--- +title: binomialCoefficient +tags: math,intermediate +--- Evaluates the binomial coefficient of two integers `n` and `k`. @@ -23,4 +26,4 @@ const binomialCoefficient = (n, k) => { ```js binomialCoefficient(8, 2); // 28 -``` +``` \ No newline at end of file diff --git a/snippets/bottomVisible.md b/snippets/bottomVisible.md index 5f358f988..009cc9d1a 100644 --- a/snippets/bottomVisible.md +++ b/snippets/bottomVisible.md @@ -1,4 +1,7 @@ -### bottomVisible +--- +title: bottomVisible +tags: browser,intermediate +--- Returns `true` if the bottom of the page is visible, `false` otherwise. @@ -12,4 +15,4 @@ const bottomVisible = () => ```js bottomVisible(); // true -``` +``` \ No newline at end of file diff --git a/snippets/btoa.md b/snippets/btoa.md index 6c4d4531f..6cbe32f46 100644 --- a/snippets/btoa.md +++ b/snippets/btoa.md @@ -1,4 +1,7 @@ -### btoa +--- +title: btoa +tags: node,string,utility,beginner +--- Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data. @@ -10,4 +13,4 @@ const btoa = str => Buffer.from(str, 'binary').toString('base64'); ```js btoa('foobar'); // 'Zm9vYmFy' -``` +``` \ No newline at end of file diff --git a/snippets/byteSize.md b/snippets/byteSize.md index 459ee3796..569f04028 100644 --- a/snippets/byteSize.md +++ b/snippets/byteSize.md @@ -1,4 +1,7 @@ -### byteSize +--- +title: byteSize +tags: string,beginner +--- Returns the length of a string in bytes. @@ -11,4 +14,4 @@ const byteSize = str => new Blob([str]).size; ```js byteSize('😀'); // 4 byteSize('Hello World'); // 11 -``` +``` \ No newline at end of file diff --git a/snippets/call.md b/snippets/call.md index 80dbaf764..98d5e0beb 100644 --- a/snippets/call.md +++ b/snippets/call.md @@ -1,13 +1,16 @@ -### call - +--- +title: call +tags: adapter,function,intermediate +--- + Given a key and a set of arguments, call them when given a context. Primarily useful in composition. -Use a closure to call a stored key with stored arguments. - +Use a closure to call a stored key with stored arguments. + ```js const call = (key, ...args) => context => context[key](...args); -``` - +``` + ```js Promise.resolve([1, 2, 3]) .then(call('map', x => 2 * x)) @@ -16,4 +19,4 @@ const map = call.bind(null, 'map'); Promise.resolve([1, 2, 3]) .then(map(x => 2 * x)) .then(console.log); // [ 2, 4, 6 ] -``` +``` \ No newline at end of file diff --git a/snippets/capitalize.md b/snippets/capitalize.md index 9997dc2a3..9669204ff 100644 --- a/snippets/capitalize.md +++ b/snippets/capitalize.md @@ -1,4 +1,7 @@ -### capitalize +--- +title: capitalize +tags: string,array,intermediate +--- Capitalizes the first letter of a string. @@ -13,4 +16,4 @@ const capitalize = ([first, ...rest], lowerRest = false) => ```js capitalize('fooBar'); // 'FooBar' capitalize('fooBar', true); // 'Foobar' -``` +``` \ No newline at end of file diff --git a/snippets/capitalizeEveryWord.md b/snippets/capitalizeEveryWord.md index 1b2afc851..89827393e 100644 --- a/snippets/capitalizeEveryWord.md +++ b/snippets/capitalizeEveryWord.md @@ -1,4 +1,7 @@ -### capitalizeEveryWord +--- +title: capitalizeEveryWord +tags: string,regexp,intermediate +--- Capitalizes the first letter of every word in a string. @@ -10,4 +13,4 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperC ```js capitalizeEveryWord('hello world!'); // 'Hello World!' -``` +``` \ No newline at end of file diff --git a/snippets/castArray.md b/snippets/castArray.md index 6af6e4907..e8c498058 100644 --- a/snippets/castArray.md +++ b/snippets/castArray.md @@ -1,4 +1,7 @@ -### castArray +--- +title: castArray +tags: utility,array,type,beginner +--- Casts the provided value as an array if it's not one. @@ -11,4 +14,4 @@ const castArray = val => (Array.isArray(val) ? val : [val]); ```js castArray('foo'); // ['foo'] castArray([1]); // [1] -``` +``` \ No newline at end of file diff --git a/snippets/chainAsync.md b/snippets/chainAsync.md index ef0b2d851..2a4048206 100644 --- a/snippets/chainAsync.md +++ b/snippets/chainAsync.md @@ -1,4 +1,7 @@ -### chainAsync +--- +title: chainAsync +tags: function,intermediate +--- Chains asynchronous functions. @@ -30,4 +33,4 @@ chainAsync([ console.log('2 second'); } ]); -``` +``` \ No newline at end of file diff --git a/snippets/checkProp.md b/snippets/checkProp.md index af0f5bdd0..a0718d22e 100644 --- a/snippets/checkProp.md +++ b/snippets/checkProp.md @@ -1,4 +1,7 @@ -### checkProp +--- +title: checkProp +tags: function,object,utility,beginner +--- Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate. @@ -9,22 +12,6 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); ``` ```js - - - - - - - - - - - - - - - - const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true @@ -42,4 +29,4 @@ const noLength(l => l === undefined, 'length'); noLength([]); // false noLength({}); // true noLength(new Set()); // true -``` +``` \ No newline at end of file diff --git a/snippets/chunk.md b/snippets/chunk.md index 633c7deda..403315e86 100644 --- a/snippets/chunk.md +++ b/snippets/chunk.md @@ -1,4 +1,7 @@ -### chunk +--- +title: chunk +tags: array,intermediate +--- Chunks an array into smaller arrays of a specified size. @@ -15,4 +18,4 @@ const chunk = (arr, size) => ```js chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]] -``` +``` \ No newline at end of file diff --git a/snippets/clampNumber.md b/snippets/clampNumber.md index 0b137c955..32fd5d1d5 100644 --- a/snippets/clampNumber.md +++ b/snippets/clampNumber.md @@ -1,4 +1,7 @@ -### clampNumber +--- +title: clampNumber +tags: math,beginner +--- Clamps `num` within the inclusive range specified by the boundary values `a` and `b`. @@ -12,4 +15,4 @@ const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math. ```js clampNumber(2, 3, 5); // 3 clampNumber(1, -1, -5); // -1 -``` +``` \ No newline at end of file diff --git a/snippets/cloneRegExp.md b/snippets/cloneRegExp.md index f6722ea3d..5c072c4e4 100644 --- a/snippets/cloneRegExp.md +++ b/snippets/cloneRegExp.md @@ -1,4 +1,7 @@ -### cloneRegExp +--- +title: cloneRegExp +tags: utility,regexp,intermediate +--- Clones a regular expression. @@ -11,4 +14,4 @@ const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); ```js const regExp = /lorem ipsum/gi; const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi -``` +``` \ No newline at end of file diff --git a/snippets/coalesce.md b/snippets/coalesce.md index 2c14c3d4f..156979331 100644 --- a/snippets/coalesce.md +++ b/snippets/coalesce.md @@ -1,4 +1,7 @@ -### coalesce +--- +title: coalesce +tags: utility,beginner +--- Returns the first non-null/undefined argument. @@ -10,4 +13,4 @@ const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)); ```js coalesce(null, undefined, '', NaN, 'Waldo'); // "" -``` +``` \ No newline at end of file diff --git a/snippets/coalesceFactory.md b/snippets/coalesceFactory.md index 565368cc5..16ef17c90 100644 --- a/snippets/coalesceFactory.md +++ b/snippets/coalesceFactory.md @@ -1,4 +1,7 @@ -### coalesceFactory +--- +title: coalesceFactory +tags: utility,intermediate +--- Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function. @@ -11,4 +14,4 @@ const coalesceFactory = valid => (...args) => args.find(valid); ```js const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo" -``` +``` \ No newline at end of file diff --git a/snippets/collectInto.md b/snippets/collectInto.md index da37626a2..82bee2047 100644 --- a/snippets/collectInto.md +++ b/snippets/collectInto.md @@ -1,17 +1,20 @@ -### collectInto - +--- +title: collectInto +tags: adapter,function,array,intermediate +--- + Changes a function that accepts an array into a variadic function. -Given a function, return a closure that collects all inputs into an array-accepting function. - +Given a function, return a closure that collects all inputs into an array-accepting function. + ```js const collectInto = fn => (...args) => fn(args); -``` - +``` + ```js const Pall = collectInto(Promise.all.bind(Promise)); let p1 = Promise.resolve(1); let p2 = Promise.resolve(2); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); Pall(p1, p2, p3).then(console.log); // [1, 2, 3] (after about 2 seconds) -``` +``` \ No newline at end of file diff --git a/snippets/colorize.md b/snippets/colorize.md index d554ce110..9f67fa468 100644 --- a/snippets/colorize.md +++ b/snippets/colorize.md @@ -1,4 +1,7 @@ -### colorize +--- +title: colorize +tags: node,utility,string,intermediate +--- Add special characters to text to print in color in the console (combined with `console.log()`). @@ -30,4 +33,4 @@ const colorize = (...args) => ({ console.log(colorize('foo').red); // 'foo' (red letters) console.log(colorize('foo', 'bar').bgBlue); // 'foo bar' (blue background) console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both) -``` +``` \ No newline at end of file diff --git a/snippets/compact.md b/snippets/compact.md index d926a56b4..f354797d0 100644 --- a/snippets/compact.md +++ b/snippets/compact.md @@ -1,4 +1,7 @@ -### compact +--- +title: compact +tags: array,beginner +--- Removes falsy values from an array. @@ -10,4 +13,4 @@ const compact = arr => arr.filter(Boolean); ```js compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); // [ 1, 2, 3, 'a', 's', 34 ] -``` +``` \ No newline at end of file diff --git a/snippets/compactWhitespace.md b/snippets/compactWhitespace.md index f8358235d..8edccc07f 100644 --- a/snippets/compactWhitespace.md +++ b/snippets/compactWhitespace.md @@ -1,4 +1,7 @@ -### compactWhitespace +--- +title: compactWhitespace +tags: string,regexp,beginner +--- Returns a string with whitespaces compacted. @@ -11,4 +14,4 @@ const compactWhitespace = str => str.replace(/\s{2,}/g, ' '); ```js compactWhitespace('Lorem Ipsum'); // 'Lorem Ipsum' compactWhitespace('Lorem \n Ipsum'); // 'Lorem Ipsum' -``` +``` \ No newline at end of file diff --git a/snippets/compose.md b/snippets/compose.md index 778e10eef..9b33d619e 100644 --- a/snippets/compose.md +++ b/snippets/compose.md @@ -1,4 +1,7 @@ -### compose +--- +title: compose +tags: function,intermediate +--- Performs right-to-left function composition. @@ -17,4 +20,4 @@ const multiplyAndAdd5 = compose( multiply ); multiplyAndAdd5(5, 2); // 15 -``` +``` \ No newline at end of file diff --git a/snippets/composeRight.md b/snippets/composeRight.md index 0270ee803..34ebdecfd 100644 --- a/snippets/composeRight.md +++ b/snippets/composeRight.md @@ -1,4 +1,7 @@ -### composeRight +--- +title: composeRight +tags: function,intermediate +--- Performs left-to-right function composition. @@ -14,4 +17,4 @@ const add = (x, y) => x + y; const square = x => x * x; const addAndSquare = composeRight(add, square); addAndSquare(1, 2); // 9 -``` +``` \ No newline at end of file diff --git a/snippets/converge.md b/snippets/converge.md index ecb328f50..ce983b10e 100644 --- a/snippets/converge.md +++ b/snippets/converge.md @@ -1,4 +1,7 @@ -### converge +--- +title: converge +tags: function,intermediate +--- Accepts a converging function and a list of branching functions and returns a function that applies each branching function to the arguments and the results of the branching functions are passed as arguments to the converging function. @@ -15,4 +18,4 @@ const average = converge((a, b) => a / b, [ arr => arr.length ]); average([1, 2, 3, 4, 5, 6, 7]); // 4 -``` +``` \ No newline at end of file diff --git a/snippets/copyToClipboard.md b/snippets/copyToClipboard.md index 343546d6e..d3d07d984 100644 --- a/snippets/copyToClipboard.md +++ b/snippets/copyToClipboard.md @@ -1,4 +1,7 @@ -### copyToClipboard +--- +title: copyToClipboard +tags: browser,string,advanced +--- ⚠️ **NOTICE:** The same functionality can be easily implemented by using the new asynchronous Clipboard API, which is still experimental but should be used in the future instead of this snippet. Find out more about it [here](https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard). @@ -33,4 +36,4 @@ const copyToClipboard = str => { ```js copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard. -``` +``` \ No newline at end of file diff --git a/snippets/countBy.md b/snippets/countBy.md index f3b7acfb4..4ec176e69 100644 --- a/snippets/countBy.md +++ b/snippets/countBy.md @@ -1,4 +1,7 @@ -### countBy +--- +title: countBy +tags: array,object,intermediate +--- Groups the elements of an array based on the given function and returns the count of elements in each group. @@ -16,4 +19,4 @@ const countBy = (arr, fn) => ```js countBy([6.1, 4.2, 6.3], Math.floor); // {4: 1, 6: 2} countBy(['one', 'two', 'three'], 'length'); // {3: 2, 5: 1} -``` +``` \ No newline at end of file diff --git a/snippets/countOccurrences.md b/snippets/countOccurrences.md index 2b57fb035..883eb03cd 100644 --- a/snippets/countOccurrences.md +++ b/snippets/countOccurrences.md @@ -1,4 +1,7 @@ -### countOccurrences +--- +title: countOccurrences +tags: array,intermediate +--- Counts the occurrences of a value in an array. @@ -10,4 +13,4 @@ const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : ```js countOccurrences([1, 1, 2, 1, 2, 3], 1); // 3 -``` +``` \ No newline at end of file diff --git a/snippets/counter.md b/snippets/counter.md index b09529e59..9e61a54fe 100644 --- a/snippets/counter.md +++ b/snippets/counter.md @@ -1,4 +1,7 @@ -### counter +--- +title: counter +tags: browser,advanced +--- Creates a counter with the specified range, step and duration for the specified selector. @@ -24,4 +27,4 @@ const counter = (selector, start, end, step = 1, duration = 2000) => { ```js counter('#my-id', 1, 1000, 5, 2000); // Creates a 2-second timer for the element with id="my-id" -``` +``` \ No newline at end of file diff --git a/snippets/createDirIfNotExists.md b/snippets/createDirIfNotExists.md index 3be54f580..417bceebf 100644 --- a/snippets/createDirIfNotExists.md +++ b/snippets/createDirIfNotExists.md @@ -1,4 +1,7 @@ -### createDirIfNotExists +--- +title: createDirIfNotExists +tags: node,beginner +--- Creates a directory, if it does not exist. @@ -11,4 +14,4 @@ const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : u ```js createDirIfNotExists('test'); // creates the directory 'test', if it doesn't exist -``` +``` \ No newline at end of file diff --git a/snippets/createElement.md b/snippets/createElement.md index cad69bb01..4f5c31242 100644 --- a/snippets/createElement.md +++ b/snippets/createElement.md @@ -1,4 +1,7 @@ -### createElement +--- +title: createElement +tags: browser,utility,beginner +--- Creates an element from a string (without appending it to the document). If the given string contains multiple elements, only the first one will be returned. @@ -22,4 +25,4 @@ const el = createElement( ` ); console.log(el.className); // 'container' -``` +``` \ No newline at end of file diff --git a/snippets/createEventHub.md b/snippets/createEventHub.md index e7c8c824c..a01d8d175 100644 --- a/snippets/createEventHub.md +++ b/snippets/createEventHub.md @@ -1,4 +1,7 @@ -### createEventHub +--- +title: createEventHub +tags: browser,event,advanced +--- Creates a pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with `emit`, `on`, and `off` methods. @@ -43,4 +46,4 @@ hub.emit('increment'); // `increment` variable is now 1 // Unsubscribe: stop a specific handler from listening to the 'message' event hub.off('message', handler); -``` +``` \ No newline at end of file diff --git a/snippets/currentURL.md b/snippets/currentURL.md index dfc6aeb13..a8eb34eac 100644 --- a/snippets/currentURL.md +++ b/snippets/currentURL.md @@ -1,4 +1,7 @@ -### currentURL +--- +title: currentURL +tags: browser,url,beginner +--- Returns the current URL. @@ -10,4 +13,4 @@ const currentURL = () => window.location.href; ```js currentURL(); // 'https://google.com' -``` +``` \ No newline at end of file diff --git a/snippets/curry.md b/snippets/curry.md index 778c77840..91714524e 100644 --- a/snippets/curry.md +++ b/snippets/curry.md @@ -1,4 +1,7 @@ -### curry +--- +title: curry +tags: function,recursion,intermediate +--- Curries a function. @@ -15,4 +18,4 @@ const curry = (fn, arity = fn.length, ...args) => ```js curry(Math.pow)(2)(10); // 1024 curry(Math.min, 3)(10)(50)(2); // 2 -``` +``` \ No newline at end of file diff --git a/snippets/dayOfYear.md b/snippets/dayOfYear.md index 7653f3481..c938b2f7d 100644 --- a/snippets/dayOfYear.md +++ b/snippets/dayOfYear.md @@ -1,4 +1,7 @@ -### dayOfYear +--- +title: dayOfYear +tags: date,beginner +--- Gets the day of the year from a `Date` object. @@ -12,4 +15,4 @@ const dayOfYear = date => ```js dayOfYear(new Date()); // 272 -``` +``` \ No newline at end of file diff --git a/snippets/debounce.md b/snippets/debounce.md index 4d4f0bb9b..3bb66b06a 100644 --- a/snippets/debounce.md +++ b/snippets/debounce.md @@ -1,4 +1,7 @@ -### debounce +--- +title: debounce +tags: function,intermediate +--- Creates a debounced function that delays invoking the provided function until at least `ms` milliseconds have elapsed since the last time it was invoked. @@ -23,4 +26,4 @@ window.addEventListener( console.log(window.innerHeight); }, 250) ); // Will log the window dimensions at most every 250ms -``` +``` \ No newline at end of file diff --git a/snippets/decapitalize.md b/snippets/decapitalize.md index a98ff5d24..a9ebeae25 100644 --- a/snippets/decapitalize.md +++ b/snippets/decapitalize.md @@ -1,4 +1,7 @@ -### decapitalize +--- +title: decapitalize +tags: string,array,intermediate +--- Decapitalizes the first letter of a string. @@ -13,4 +16,4 @@ const decapitalize = ([first, ...rest], upperRest = false) => ```js decapitalize('FooBar'); // 'fooBar' decapitalize('FooBar', true); // 'fOOBAR' -``` +``` \ No newline at end of file diff --git a/snippets/deepClone.md b/snippets/deepClone.md index 2b47cdb51..9edfd363f 100644 --- a/snippets/deepClone.md +++ b/snippets/deepClone.md @@ -1,4 +1,7 @@ -### deepClone +--- +title: deepClone +tags: object,recursion,intermediate +--- Creates a deep clone of an object. @@ -23,4 +26,4 @@ const deepClone = obj => { ```js const a = { foo: 'bar', obj: { a: 1, b: 2 } }; const b = deepClone(a); // a !== b, a.obj !== b.obj -``` +``` \ No newline at end of file diff --git a/snippets/deepFlatten.md b/snippets/deepFlatten.md index 28f275203..a1f36eb39 100644 --- a/snippets/deepFlatten.md +++ b/snippets/deepFlatten.md @@ -1,4 +1,7 @@ -### deepFlatten +--- +title: deepFlatten +tags: array,recursion,intermediate +--- Deep flattens an array. @@ -12,4 +15,4 @@ const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFla ```js deepFlatten([1, [2], [[3], 4], 5]); // [1,2,3,4,5] -``` +``` \ No newline at end of file diff --git a/snippets/deepFreeze.md b/snippets/deepFreeze.md index fe87461e1..f5b0b759c 100644 --- a/snippets/deepFreeze.md +++ b/snippets/deepFreeze.md @@ -1,4 +1,7 @@ -### deepFreeze +--- +title: deepFreeze +tags: object,recursion,intermediate +--- Deep freezes an object. @@ -19,4 +22,4 @@ const o = deepFreeze([1, [2, 3]]); o[0] = 3; // not allowed o[1][0] = 4; // not allowed as well -``` +``` \ No newline at end of file diff --git a/snippets/deepGet.md b/snippets/deepGet.md index 2b25719f9..9327557c8 100644 --- a/snippets/deepGet.md +++ b/snippets/deepGet.md @@ -1,4 +1,7 @@ -### deepGet +--- +title: deepGet +tags: object,intermediate +--- Returns the target value in a nested JSON object, based on the `keys` array. @@ -22,4 +25,4 @@ const data = { }; deepGet(data, ['foo', 'foz', index]); // get 3 deepGet(data, ['foo', 'bar', 'baz', 8, 'foz']); // null -``` +``` \ No newline at end of file diff --git a/snippets/deepMapKeys.md b/snippets/deepMapKeys.md index c736420ee..d2ea1cca1 100644 --- a/snippets/deepMapKeys.md +++ b/snippets/deepMapKeys.md @@ -1,4 +1,7 @@ -### deepMapKeys +--- +title: deepMapKeys +tags: object,recursion,advanced +--- Deep maps an object keys. @@ -49,4 +52,4 @@ const upperKeysObj = deepMapKeys(obj, key => key.toUpperCase()); } } */ -``` +``` \ No newline at end of file diff --git a/snippets/defaults.md b/snippets/defaults.md index e083bb470..a48d3311d 100644 --- a/snippets/defaults.md +++ b/snippets/defaults.md @@ -1,4 +1,7 @@ -### defaults +--- +title: defaults +tags: object,intermediate +--- Assigns default values for all properties in an object that are `undefined`. @@ -10,4 +13,4 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj ```js defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 } -``` +``` \ No newline at end of file diff --git a/snippets/defer.md b/snippets/defer.md index e6cd03052..5ad0f99f4 100644 --- a/snippets/defer.md +++ b/snippets/defer.md @@ -1,4 +1,7 @@ -### defer +--- +title: defer +tags: function,intermediate +--- Defers invoking a function until the current call stack has cleared. @@ -16,4 +19,4 @@ defer(console.log, 'a'), console.log('b'); // logs 'b' then 'a' document.querySelector('#someElement').innerHTML = 'Hello'; longRunningFunction(); // Browser will not update the HTML until this has finished defer(longRunningFunction); // Browser will update the HTML then run the function -``` +``` \ No newline at end of file diff --git a/snippets/degreesToRads.md b/snippets/degreesToRads.md index 90790765d..5c8efde0e 100644 --- a/snippets/degreesToRads.md +++ b/snippets/degreesToRads.md @@ -1,4 +1,7 @@ -### degreesToRads +--- +title: degreesToRads +tags: math,beginner +--- Converts an angle from degrees to radians. @@ -10,4 +13,4 @@ const degreesToRads = deg => (deg * Math.PI) / 180.0; ```js degreesToRads(90.0); // ~1.5708 -``` +``` \ No newline at end of file diff --git a/snippets/delay.md b/snippets/delay.md index da524837f..0da2c89dc 100644 --- a/snippets/delay.md +++ b/snippets/delay.md @@ -1,4 +1,7 @@ -### delay +--- +title: delay +tags: function,intermediate +--- Invokes the provided function after `wait` milliseconds. @@ -17,4 +20,4 @@ delay( 1000, 'later' ); // Logs 'later' after one second. -``` +``` \ No newline at end of file diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md index 6b7bf083d..7ead08557 100644 --- a/snippets/detectDeviceType.md +++ b/snippets/detectDeviceType.md @@ -1,4 +1,7 @@ -### detectDeviceType +--- +title: detectDeviceType +tags: browser,intermediate +--- Detects whether the website is being opened in a mobile device or a desktop/laptop. @@ -13,4 +16,4 @@ const detectDeviceType = () => ```js detectDeviceType(); // "Mobile" or "Desktop" -``` +``` \ No newline at end of file diff --git a/snippets/difference.md b/snippets/difference.md index 6d17318ad..e732cc06f 100644 --- a/snippets/difference.md +++ b/snippets/difference.md @@ -1,4 +1,7 @@ -### difference +--- +title: difference +tags: array,math,beginner +--- Returns the difference between two arrays. @@ -13,4 +16,4 @@ const difference = (a, b) => { ```js difference([1, 2, 3], [1, 2, 4]); // [3] -``` +``` \ No newline at end of file diff --git a/snippets/differenceBy.md b/snippets/differenceBy.md index b304aab38..9e17a1a5c 100644 --- a/snippets/differenceBy.md +++ b/snippets/differenceBy.md @@ -1,4 +1,7 @@ -### differenceBy +--- +title: differenceBy +tags: array,function,intermediate +--- Returns the difference between two arrays, after applying the provided function to each array element of both. @@ -14,4 +17,4 @@ const differenceBy = (a, b, fn) => { ```js differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1] differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [2] -``` +``` \ No newline at end of file diff --git a/snippets/differenceWith.md b/snippets/differenceWith.md index 66d631341..3aede6b6d 100644 --- a/snippets/differenceWith.md +++ b/snippets/differenceWith.md @@ -1,4 +1,7 @@ -### differenceWith +--- +title: differenceWith +tags: array,function,intermediate +--- Filters out all values from an array for which the comparator function does not return `true`. @@ -10,4 +13,4 @@ const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => co ```js differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2] -``` +``` \ No newline at end of file diff --git a/snippets/dig.md b/snippets/dig.md index 737130b6e..4484cdd6f 100644 --- a/snippets/dig.md +++ b/snippets/dig.md @@ -1,4 +1,7 @@ -### dig +--- +title: dig +tags: object,recursion,intermediate +--- Returns the target value in a nested JSON object, based on the given key. @@ -25,4 +28,4 @@ const data = { }; dig(data, 'level3'); // 'some data' dig(data, 'level4'); // undefined -``` +``` \ No newline at end of file diff --git a/snippets/digitize.md b/snippets/digitize.md index 4f51a6f23..c7be2ac1e 100644 --- a/snippets/digitize.md +++ b/snippets/digitize.md @@ -1,4 +1,7 @@ -### digitize +--- +title: digitize +tags: math,array,beginner +--- Converts a number to an array of digits. @@ -11,4 +14,4 @@ const digitize = n => [...`${n}`].map(i => parseInt(i)); ```js digitize(123); // [1, 2, 3] -``` +``` \ No newline at end of file diff --git a/snippets/distance.md b/snippets/distance.md index b0b9baa2b..d1b08f228 100644 --- a/snippets/distance.md +++ b/snippets/distance.md @@ -1,4 +1,7 @@ -### distance +--- +title: distance +tags: math,beginner +--- Returns the distance between two points. @@ -10,4 +13,4 @@ const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); ```js distance(1, 1, 2, 3); // 2.23606797749979 -``` +``` \ No newline at end of file diff --git a/snippets/drop.md b/snippets/drop.md index 0e4b31d1e..e96bcb973 100644 --- a/snippets/drop.md +++ b/snippets/drop.md @@ -1,4 +1,7 @@ -### drop +--- +title: drop +tags: array,beginner +--- Returns a new array with `n` elements removed from the left. @@ -12,4 +15,4 @@ const drop = (arr, n = 1) => arr.slice(n); drop([1, 2, 3]); // [2,3] drop([1, 2, 3], 2); // [3] drop([1, 2, 3], 42); // [] -``` +``` \ No newline at end of file diff --git a/snippets/dropRight.md b/snippets/dropRight.md index 83b3a4c20..4e42cf0ce 100644 --- a/snippets/dropRight.md +++ b/snippets/dropRight.md @@ -1,4 +1,7 @@ -### dropRight +--- +title: dropRight +tags: array,beginner +--- Returns a new array with `n` elements removed from the right. @@ -12,4 +15,4 @@ const dropRight = (arr, n = 1) => arr.slice(0, -n); dropRight([1, 2, 3]); // [1,2] dropRight([1, 2, 3], 2); // [1] dropRight([1, 2, 3], 42); // [] -``` +``` \ No newline at end of file diff --git a/snippets/dropRightWhile.md b/snippets/dropRightWhile.md index 4242132da..17f963829 100644 --- a/snippets/dropRightWhile.md +++ b/snippets/dropRightWhile.md @@ -1,4 +1,7 @@ -### dropRightWhile +--- +title: dropRightWhile +tags: array,function,intermediate +--- Removes elements from the end of an array until the passed function returns `true`. Returns the remaining elements in the array. @@ -15,4 +18,4 @@ const dropRightWhile = (arr, func) => { ```js dropRightWhile([1, 2, 3, 4], n => n < 3); // [1, 2] -``` +``` \ No newline at end of file diff --git a/snippets/dropWhile.md b/snippets/dropWhile.md index 6ed952eff..f7263b384 100644 --- a/snippets/dropWhile.md +++ b/snippets/dropWhile.md @@ -1,4 +1,7 @@ -### dropWhile +--- +title: dropWhile +tags: array,function,intermediate +--- Removes elements in an array until the passed function returns `true`. Returns the remaining elements in the array. @@ -14,4 +17,4 @@ const dropWhile = (arr, func) => { ```js dropWhile([1, 2, 3, 4], n => n >= 3); // [3,4] -``` +``` \ No newline at end of file diff --git a/snippets/elementContains.md b/snippets/elementContains.md index b4be15600..f45127a8f 100644 --- a/snippets/elementContains.md +++ b/snippets/elementContains.md @@ -1,4 +1,7 @@ -### elementContains +--- +title: elementContains +tags: browser,intermediate +--- Returns `true` if the `parent` element contains the `child` element, `false` otherwise. @@ -11,4 +14,4 @@ const elementContains = (parent, child) => parent !== child && parent.contains(c ```js elementContains(document.querySelector('head'), document.querySelector('title')); // true elementContains(document.querySelector('body'), document.querySelector('body')); // false -``` +``` \ No newline at end of file diff --git a/snippets/elementIsVisibleInViewport.md b/snippets/elementIsVisibleInViewport.md index abb45b307..5bd4305a8 100644 --- a/snippets/elementIsVisibleInViewport.md +++ b/snippets/elementIsVisibleInViewport.md @@ -1,4 +1,7 @@ -### elementIsVisibleInViewport +--- +title: elementIsVisibleInViewport +tags: browser,advanced +--- Returns `true` if the element specified is visible in the viewport, `false` otherwise. @@ -22,4 +25,4 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => { // 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, true); // true - (partially visible) -``` +``` \ No newline at end of file diff --git a/snippets/elo.md b/snippets/elo.md index 77f211651..f7cde495d 100644 --- a/snippets/elo.md +++ b/snippets/elo.md @@ -1,4 +1,7 @@ -### elo +--- +title: elo +tags: math,array,advanced +--- Computes the new ratings between two or more opponents using the [Elo rating system](https://en.wikipedia.org/wiki/Elo_rating_system). It takes an array of pre-ratings and returns an array containing post-ratings. @@ -39,4 +42,4 @@ For teams, each rating can adjusted based on own team's average rating vs. average rating of opposing team, with the score being added to their own individual rating by supplying it as the third argument. */ -``` +``` \ No newline at end of file diff --git a/snippets/equals.md b/snippets/equals.md index 39082bff3..819a1e38d 100644 --- a/snippets/equals.md +++ b/snippets/equals.md @@ -1,4 +1,7 @@ -### equals +--- +title: equals +tags: object,array,type,advanced +--- Performs a deep comparison between two values to determine if they are equivalent. @@ -21,4 +24,4 @@ const equals = (a, b) => { ```js equals({ a: [2, { e: 3 }], b: [4], c: 'foo' }, { a: [2, { e: 3 }], b: [4], c: 'foo' }); // true -``` +``` \ No newline at end of file diff --git a/snippets/escapeHTML.md b/snippets/escapeHTML.md index 37ab7f395..70560804e 100644 --- a/snippets/escapeHTML.md +++ b/snippets/escapeHTML.md @@ -1,4 +1,7 @@ -### escapeHTML +--- +title: escapeHTML +tags: string,browser,regexp,intermediate +--- Escapes a string for use in HTML. @@ -21,4 +24,4 @@ const escapeHTML = str => ```js escapeHTML('Me & you'); // '<a href="#">Me & you</a>' -``` +``` \ No newline at end of file diff --git a/snippets/escapeRegExp.md b/snippets/escapeRegExp.md index 066e2292a..ce05d6cc8 100644 --- a/snippets/escapeRegExp.md +++ b/snippets/escapeRegExp.md @@ -1,4 +1,7 @@ -### escapeRegExp +--- +title: escapeRegExp +tags: string,regexp,intermediate +--- Escapes a string to use in a regular expression. @@ -10,4 +13,4 @@ const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); ```js escapeRegExp('(test)'); // \\(test\\) -``` +``` \ No newline at end of file diff --git a/snippets/everyNth.md b/snippets/everyNth.md index f3fbb6fb6..a064f8980 100644 --- a/snippets/everyNth.md +++ b/snippets/everyNth.md @@ -1,4 +1,7 @@ -### everyNth +--- +title: everyNth +tags: array,beginner +--- Returns every nth element in an array. @@ -10,4 +13,4 @@ const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1); ```js everyNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ] -``` +``` \ No newline at end of file diff --git a/snippets/extendHex.md b/snippets/extendHex.md index 73fa01e9b..4fc24af82 100644 --- a/snippets/extendHex.md +++ b/snippets/extendHex.md @@ -1,4 +1,7 @@ -### extendHex +--- +title: extendHex +tags: utility,string,intermediate +--- Extends a 3-digit color code to a 6-digit color code. @@ -18,4 +21,4 @@ const extendHex = shortHex => ```js extendHex('#03f'); // '#0033ff' extendHex('05a'); // '#0055aa' -``` +``` \ No newline at end of file diff --git a/snippets/factorial.md b/snippets/factorial.md index cf3acc9cc..461dbd4f1 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -1,4 +1,7 @@ -### factorial +--- +title: factorial +tags: math,recursion,beginner +--- Calculates the factorial of a number. @@ -20,4 +23,4 @@ const factorial = n => ```js factorial(6); // 720 -``` +``` \ No newline at end of file diff --git a/snippets/fibonacci.md b/snippets/fibonacci.md index 9f6454b1c..c08b03733 100644 --- a/snippets/fibonacci.md +++ b/snippets/fibonacci.md @@ -1,4 +1,7 @@ -### fibonacci +--- +title: fibonacci +tags: math,array,beginner +--- Generates an array, containing the Fibonacci sequence, up until the nth term. @@ -15,4 +18,4 @@ const fibonacci = n => ```js fibonacci(6); // [0, 1, 1, 2, 3, 5] -``` +``` \ No newline at end of file diff --git a/snippets/filterFalsy.md b/snippets/filterFalsy.md index 3208e39c8..dfa9209de 100755 --- a/snippets/filterFalsy.md +++ b/snippets/filterFalsy.md @@ -1,13 +1,16 @@ -### filterFalsy - +--- +title: filterFalsy +tags: array,beginner +--- + Filters out the falsy values in an array. -Use `Array.prototype.filter()` to get an array containing only truthy values. - +Use `Array.prototype.filter()` to get an array containing only truthy values. + ```js const filterFalsy = arr => arr.filter(Boolean); -``` - +``` + ```js filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1] -``` +``` \ No newline at end of file diff --git a/snippets/filterNonUnique.md b/snippets/filterNonUnique.md index 970ff0175..d68ece039 100644 --- a/snippets/filterNonUnique.md +++ b/snippets/filterNonUnique.md @@ -1,4 +1,7 @@ -### filterNonUnique +--- +title: filterNonUnique +tags: array,beginner +--- Filters out the non-unique values in an array. @@ -10,4 +13,4 @@ const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexO ```js filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1, 3, 5] -``` +``` \ No newline at end of file diff --git a/snippets/filterNonUniqueBy.md b/snippets/filterNonUniqueBy.md index d3867214a..583d15c23 100644 --- a/snippets/filterNonUniqueBy.md +++ b/snippets/filterNonUniqueBy.md @@ -1,4 +1,7 @@ -### filterNonUniqueBy +--- +title: filterNonUniqueBy +tags: array,function,intermediate +--- Filters out the non-unique values in an array, based on a provided comparator function. @@ -21,4 +24,4 @@ filterNonUniqueBy( ], (a, b) => a.id == b.id ); // [ { id: 2, value: 'c' } ] -``` +``` \ No newline at end of file diff --git a/snippets/findKey.md b/snippets/findKey.md index 6e25b7ac2..17c441072 100644 --- a/snippets/findKey.md +++ b/snippets/findKey.md @@ -1,4 +1,7 @@ -### findKey +--- +title: findKey +tags: object,function,intermediate +--- Returns the first key that satisfies the provided testing function. Otherwise `undefined` is returned. @@ -17,4 +20,4 @@ findKey( }, o => o['active'] ); // 'barney' -``` +``` \ No newline at end of file diff --git a/snippets/findLast.md b/snippets/findLast.md index 23ef6aba5..adb7b1579 100644 --- a/snippets/findLast.md +++ b/snippets/findLast.md @@ -1,4 +1,7 @@ -### findLast +--- +title: findLast +tags: array,beginner +--- Returns the last element for which the provided function returns a truthy value. @@ -10,4 +13,4 @@ const findLast = (arr, fn) => arr.filter(fn).pop(); ```js findLast([1, 2, 3, 4], n => n % 2 === 1); // 3 -``` +``` \ No newline at end of file diff --git a/snippets/findLastIndex.md b/snippets/findLastIndex.md index e0d029920..12f28746e 100644 --- a/snippets/findLastIndex.md +++ b/snippets/findLastIndex.md @@ -1,4 +1,7 @@ -### findLastIndex +--- +title: findLastIndex +tags: array,function,intermediate +--- Returns the index of the last element for which the provided function returns a truthy value. @@ -17,4 +20,4 @@ const findLastIndex = (arr, fn) => ```js findLastIndex([1, 2, 3, 4], n => n % 2 === 1); // 2 (index of the value 3) findLastIndex([1, 2, 3, 4], n => n === 5); // -1 (default value when not found) -``` +``` \ No newline at end of file diff --git a/snippets/findLastKey.md b/snippets/findLastKey.md index 0787e4bab..8d6f8ce03 100644 --- a/snippets/findLastKey.md +++ b/snippets/findLastKey.md @@ -1,4 +1,7 @@ -### findLastKey +--- +title: findLastKey +tags: object,function,intermediate +--- Returns the last key that satisfies the provided testing function. Otherwise `undefined` is returned. @@ -22,4 +25,4 @@ findLastKey( }, o => o['active'] ); // 'pebbles' -``` +``` \ No newline at end of file diff --git a/snippets/flatten.md b/snippets/flatten.md index 4493d5418..4b8c78170 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -1,4 +1,7 @@ -### flatten +--- +title: flatten +tags: array,intermediate +--- Flattens an array up to the specified depth. @@ -15,4 +18,4 @@ const flatten = (arr, depth = 1) => ```js flatten([1, [2], 3, 4]); // [1, 2, 3, 4] flatten([1, [2, [3, [4, 5], 6], 7], 8], 2); // [1, 2, 3, [4, 5], 6, 7, 8] -``` +``` \ No newline at end of file diff --git a/snippets/flattenObject.md b/snippets/flattenObject.md index 5935d8e66..ce47de292 100644 --- a/snippets/flattenObject.md +++ b/snippets/flattenObject.md @@ -1,4 +1,7 @@ -### flattenObject +--- +title: flattenObject +tags: object,recursion,intermediate +--- Flatten an object with the paths for keys. @@ -20,4 +23,4 @@ const flattenObject = (obj, prefix = '') => ```js flattenObject({ a: { b: { c: 1 } }, d: 1 }); // { 'a.b.c': 1, d: 1 } -``` +``` \ No newline at end of file diff --git a/snippets/flip.md b/snippets/flip.md index 109471dba..a6419f811 100644 --- a/snippets/flip.md +++ b/snippets/flip.md @@ -1,13 +1,16 @@ -### flip - +--- +title: flip +tags: adapter,function,intermediate +--- + Flip takes a function as an argument, then makes the first argument the last. -Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. - +Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. + ```js const flip = fn => (first, ...rest) => fn(...rest, first); -``` - +``` + ```js let a = { name: 'John Smith' }; let b = {}; @@ -16,4 +19,4 @@ let mergePerson = mergeFrom.bind(null, a); mergePerson(b); // == b b = {}; Object.assign(b, a); // == b -``` +``` \ No newline at end of file diff --git a/snippets/forEachRight.md b/snippets/forEachRight.md index cc4ab9d38..6ea365747 100644 --- a/snippets/forEachRight.md +++ b/snippets/forEachRight.md @@ -1,4 +1,7 @@ -### forEachRight +--- +title: forEachRight +tags: array,function,intermediate +--- Executes a provided function once for each array element, starting from the array's last element. @@ -14,4 +17,4 @@ const forEachRight = (arr, callback) => ```js forEachRight([1, 2, 3, 4], val => console.log(val)); // '4', '3', '2', '1' -``` +``` \ No newline at end of file diff --git a/snippets/forOwn.md b/snippets/forOwn.md index 25f70e293..2d1c7cf9b 100644 --- a/snippets/forOwn.md +++ b/snippets/forOwn.md @@ -1,4 +1,7 @@ -### forOwn +--- +title: forOwn +tags: object,intermediate +--- Iterates over all own properties of an object, running a callback for each one. @@ -10,4 +13,4 @@ const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, ob ```js forOwn({ foo: 'bar', a: 1 }, v => console.log(v)); // 'bar', 1 -``` +``` \ No newline at end of file diff --git a/snippets/forOwnRight.md b/snippets/forOwnRight.md index ad55592eb..433e333e2 100644 --- a/snippets/forOwnRight.md +++ b/snippets/forOwnRight.md @@ -1,4 +1,7 @@ -### forOwnRight +--- +title: forOwnRight +tags: object,intermediate +--- Iterates over all own properties of an object in reverse, running a callback for each one. @@ -13,4 +16,4 @@ const forOwnRight = (obj, fn) => ```js forOwnRight({ foo: 'bar', a: 1 }, v => console.log(v)); // 1, 'bar' -``` +``` \ No newline at end of file diff --git a/snippets/formToObject.md b/snippets/formToObject.md index c0f83acd5..65cee7564 100644 --- a/snippets/formToObject.md +++ b/snippets/formToObject.md @@ -1,4 +1,7 @@ -### formToObject +--- +title: formToObject +tags: browser,object,intermediate +--- Encode a set of form elements as an `object`. @@ -18,4 +21,4 @@ const formToObject = form => ```js formToObject(document.querySelector('#form')); // { email: 'test@email.com', name: 'Test Name' } -``` +``` \ No newline at end of file diff --git a/snippets/formatDuration.md b/snippets/formatDuration.md index 60c723083..48b3e5df8 100644 --- a/snippets/formatDuration.md +++ b/snippets/formatDuration.md @@ -1,4 +1,7 @@ -### formatDuration +--- +title: formatDuration +tags: date,math,string,utility,intermediate +--- Returns the human readable format of the given number of milliseconds. @@ -27,4 +30,4 @@ const formatDuration = ms => { ```js formatDuration(1001); // '1 second, 1 millisecond' formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds' -``` +``` \ No newline at end of file diff --git a/snippets/fromCamelCase.md b/snippets/fromCamelCase.md index 82923b239..f1aa72e7a 100644 --- a/snippets/fromCamelCase.md +++ b/snippets/fromCamelCase.md @@ -1,4 +1,7 @@ -### fromCamelCase +--- +title: fromCamelCase +tags: string,intermediate +--- Converts a string from camelcase. @@ -17,4 +20,4 @@ const fromCamelCase = (str, separator = '_') => fromCamelCase('someDatabaseFieldName', ' '); // 'some database field name' fromCamelCase('someLabelThatNeedsToBeCamelized', '-'); // 'some-label-that-needs-to-be-camelized' fromCamelCase('someJavascriptProperty', '_'); // 'some_javascript_property' -``` +``` \ No newline at end of file diff --git a/snippets/functionName.md b/snippets/functionName.md index 06a32dc39..0811b550b 100644 --- a/snippets/functionName.md +++ b/snippets/functionName.md @@ -1,4 +1,7 @@ -### functionName +--- +title: functionName +tags: function,utility,beginner +--- Logs the name of a function. @@ -10,4 +13,4 @@ const functionName = fn => (console.debug(fn.name), fn); ```js functionName(Math.max); // max (logged in debug channel of console) -``` +``` \ No newline at end of file diff --git a/snippets/functions.md b/snippets/functions.md index 405e8cf80..06ae6bdfd 100644 --- a/snippets/functions.md +++ b/snippets/functions.md @@ -1,4 +1,7 @@ -### functions +--- +title: functions +tags: object,function,intermediate +--- Returns an array of function property names from own (and optionally inherited) enumerable properties of an object. @@ -23,4 +26,4 @@ function Foo() { Foo.prototype.c = () => 3; functions(new Foo()); // ['a', 'b'] functions(new Foo(), true); // ['a', 'b', 'c'] -``` +``` \ No newline at end of file diff --git a/snippets/gcd.md b/snippets/gcd.md index 5b3f7a29a..9df1d6e5a 100644 --- a/snippets/gcd.md +++ b/snippets/gcd.md @@ -1,4 +1,7 @@ -### gcd +--- +title: gcd +tags: math,recursion,beginner +--- Calculates the greatest common divisor between two or more numbers/arrays. @@ -16,4 +19,4 @@ const gcd = (...arr) => { ```js gcd(8, 36); // 4 gcd(...[12, 8, 32]); // 4 -``` +``` \ No newline at end of file diff --git a/snippets/geometricProgression.md b/snippets/geometricProgression.md index 382471e95..6a85c504e 100644 --- a/snippets/geometricProgression.md +++ b/snippets/geometricProgression.md @@ -1,4 +1,7 @@ -### geometricProgression +--- +title: geometricProgression +tags: math,intermediate +--- 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`. @@ -18,4 +21,4 @@ const geometricProgression = (end, start = 1, step = 2) => geometricProgression(256); // [1, 2, 4, 8, 16, 32, 64, 128, 256] geometricProgression(256, 3); // [3, 6, 12, 24, 48, 96, 192] geometricProgression(256, 1, 4); // [1, 4, 16, 64, 256] -``` +``` \ No newline at end of file diff --git a/snippets/get.md b/snippets/get.md index fec1f4759..b483a771e 100644 --- a/snippets/get.md +++ b/snippets/get.md @@ -1,4 +1,7 @@ -### get +--- +title: get +tags: object,intermediate +--- Retrieve a set of properties indicated by the given selectors from an object. @@ -18,4 +21,4 @@ const get = (from, ...selectors) => ```js const obj = { selector: { to: { val: 'val to select' } }, target: [1, 2, { a: 'test' }] }; get(obj, 'selector.to.val', 'target[0]', 'target[2].a'); // ['val to select', 1, 'test'] -``` +``` \ No newline at end of file diff --git a/snippets/getColonTimeFromDate.md b/snippets/getColonTimeFromDate.md index 06ce92ea6..0691667c4 100644 --- a/snippets/getColonTimeFromDate.md +++ b/snippets/getColonTimeFromDate.md @@ -1,4 +1,7 @@ -### getColonTimeFromDate +--- +title: getColonTimeFromDate +tags: date,intermediate +--- Returns a string of the form `HH:MM:SS` from a `Date` object. @@ -10,4 +13,4 @@ const getColonTimeFromDate = date => date.toTimeString().slice(0, 8); ```js getColonTimeFromDate(new Date()); // "08:38:00" -``` +``` \ No newline at end of file diff --git a/snippets/getDaysDiffBetweenDates.md b/snippets/getDaysDiffBetweenDates.md index 898efdffb..f316bc8ea 100644 --- a/snippets/getDaysDiffBetweenDates.md +++ b/snippets/getDaysDiffBetweenDates.md @@ -1,4 +1,7 @@ -### getDaysDiffBetweenDates +--- +title: getDaysDiffBetweenDates +tags: date,intermediate +--- Returns the difference (in days) between two dates. @@ -11,4 +14,4 @@ const getDaysDiffBetweenDates = (dateInitial, dateFinal) => ```js getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9 -``` +``` \ No newline at end of file diff --git a/snippets/getImages.md b/snippets/getImages.md index d7b620777..be78b7cc7 100644 --- a/snippets/getImages.md +++ b/snippets/getImages.md @@ -1,4 +1,7 @@ -### getImages +--- +title: getImages +tags: browser,beginner +--- Fetches all images from within an element and puts them into an array @@ -14,4 +17,4 @@ const getImages = (el, includeDuplicates = false) => { ```js getImages(document, true); // ['image1.jpg', 'image2.png', 'image1.png', '...'] getImages(document, false); // ['image1.jpg', 'image2.png', '...'] -``` +``` \ No newline at end of file diff --git a/snippets/getMeridiemSuffixOfInteger.md b/snippets/getMeridiemSuffixOfInteger.md index 9cf6e46c3..1d9c01ee0 100644 --- a/snippets/getMeridiemSuffixOfInteger.md +++ b/snippets/getMeridiemSuffixOfInteger.md @@ -1,4 +1,7 @@ -### getMeridiemSuffixOfInteger +--- +title: getMeridiemSuffixOfInteger +tags: date,beginner +--- Converts an integer to a suffixed string, adding `am` or `pm` based on its value. @@ -20,4 +23,4 @@ getMeridiemSuffixOfInteger(0); // "12am" getMeridiemSuffixOfInteger(11); // "11am" getMeridiemSuffixOfInteger(13); // "1pm" getMeridiemSuffixOfInteger(25); // "1pm" -``` +``` \ No newline at end of file diff --git a/snippets/getScrollPosition.md b/snippets/getScrollPosition.md index f635a5a1f..91cad1847 100644 --- a/snippets/getScrollPosition.md +++ b/snippets/getScrollPosition.md @@ -1,4 +1,7 @@ -### getScrollPosition +--- +title: getScrollPosition +tags: browser,intermediate +--- Returns the scroll position of the current page. @@ -14,4 +17,4 @@ const getScrollPosition = (el = window) => ({ ```js getScrollPosition(); // {x: 0, y: 200} -``` +``` \ No newline at end of file diff --git a/snippets/getStyle.md b/snippets/getStyle.md index ee9456a69..aa70f0ebc 100644 --- a/snippets/getStyle.md +++ b/snippets/getStyle.md @@ -1,4 +1,7 @@ -### getStyle +--- +title: getStyle +tags: browser,css,beginner +--- Returns the value of a CSS rule for the specified element. @@ -10,4 +13,4 @@ const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName]; ```js getStyle(document.querySelector('p'), 'font-size'); // '16px' -``` +``` \ No newline at end of file diff --git a/snippets/getType.md b/snippets/getType.md index ceb09c12d..381df31c3 100644 --- a/snippets/getType.md +++ b/snippets/getType.md @@ -1,4 +1,7 @@ -### getType +--- +title: getType +tags: type,beginner +--- Returns the native type of a value. @@ -11,4 +14,4 @@ const getType = v => ```js getType(new Set([1, 2, 3])); // 'set' -``` +``` \ No newline at end of file diff --git a/snippets/getURLParameters.md b/snippets/getURLParameters.md index 93d7fc86d..287abebb8 100644 --- a/snippets/getURLParameters.md +++ b/snippets/getURLParameters.md @@ -1,4 +1,7 @@ -### getURLParameters +--- +title: getURLParameters +tags: utility,browser,string,url,intermediate +--- Returns an object containing the parameters of the current URL. @@ -16,4 +19,4 @@ const getURLParameters = url => ```js getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'} getURLParameters('google.com'); // {} -``` +``` \ No newline at end of file diff --git a/snippets/groupBy.md b/snippets/groupBy.md index 200c9711d..cbdab1e11 100644 --- a/snippets/groupBy.md +++ b/snippets/groupBy.md @@ -1,4 +1,7 @@ -### groupBy +--- +title: groupBy +tags: array,object,intermediate +--- Groups the elements of an array based on the given function. @@ -16,4 +19,4 @@ const groupBy = (arr, fn) => ```js groupBy([6.1, 4.2, 6.3], Math.floor); // {4: [4.2], 6: [6.1, 6.3]} groupBy(['one', 'two', 'three'], 'length'); // {3: ['one', 'two'], 5: ['three']} -``` +``` \ No newline at end of file diff --git a/snippets/hammingDistance.md b/snippets/hammingDistance.md index 69c34e254..f95e80d90 100644 --- a/snippets/hammingDistance.md +++ b/snippets/hammingDistance.md @@ -1,4 +1,7 @@ -### hammingDistance +--- +title: hammingDistance +tags: math,beginner +--- Calculates the Hamming distance between two values. @@ -11,4 +14,4 @@ const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) | ```js hammingDistance(2, 3); // 1 -``` +``` \ No newline at end of file diff --git a/snippets/hasClass.md b/snippets/hasClass.md index eb3fc086d..31a8502a0 100644 --- a/snippets/hasClass.md +++ b/snippets/hasClass.md @@ -1,4 +1,7 @@ -### hasClass +--- +title: hasClass +tags: browser,css,beginner +--- Returns `true` if the element has the specified class, `false` otherwise. @@ -10,4 +13,4 @@ const hasClass = (el, className) => el.classList.contains(className); ```js hasClass(document.querySelector('p.special'), 'special'); // true -``` +``` \ No newline at end of file diff --git a/snippets/hasFlags.md b/snippets/hasFlags.md index 19aa9262b..b72a2e58c 100644 --- a/snippets/hasFlags.md +++ b/snippets/hasFlags.md @@ -1,4 +1,7 @@ -### hasFlags +--- +title: hasFlags +tags: node,intermediate +--- Check if the current process's arguments contain the specified flags. @@ -15,4 +18,4 @@ const hasFlags = (...flags) => hasFlags('-s'); // true hasFlags('--test', 'cool=true', '-s'); // true hasFlags('special'); // false -``` +``` \ No newline at end of file diff --git a/snippets/hashBrowser.md b/snippets/hashBrowser.md index 38e4d978c..91c7741dc 100644 --- a/snippets/hashBrowser.md +++ b/snippets/hashBrowser.md @@ -1,4 +1,7 @@ -### hashBrowser +--- +title: hashBrowser +tags: browser,utility,advanced,promise,advanced +--- Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise. @@ -17,4 +20,4 @@ const hashBrowser = val => ```js hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393' -``` +``` \ No newline at end of file diff --git a/snippets/hashNode.md b/snippets/hashNode.md index 072ed1b2f..b29ba3814 100644 --- a/snippets/hashNode.md +++ b/snippets/hashNode.md @@ -1,4 +1,7 @@ -### hashNode +--- +title: hashNode +tags: node,utility,promise,intermediate +--- Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise. @@ -23,4 +26,4 @@ const hashNode = val => ```js hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393' -``` +``` \ No newline at end of file diff --git a/snippets/head.md b/snippets/head.md index e1832122a..9fdaefdbf 100644 --- a/snippets/head.md +++ b/snippets/head.md @@ -1,4 +1,7 @@ -### head +--- +title: head +tags: array,beginner +--- Returns the head of a list. @@ -10,4 +13,4 @@ const head = arr => arr[0]; ```js head([1, 2, 3]); // 1 -``` +``` \ No newline at end of file diff --git a/snippets/hexToRGB.md b/snippets/hexToRGB.md index 2401eb7f0..0638ea9c9 100644 --- a/snippets/hexToRGB.md +++ b/snippets/hexToRGB.md @@ -1,4 +1,7 @@ -### hexToRGB +--- +title: hexToRGB +tags: utility,string,math,advanced +--- Converts a color code to a `rgb()` or `rgba()` string if alpha value is provided. @@ -30,4 +33,4 @@ const hexToRGB = hex => { hexToRGB('#27ae60ff'); // 'rgba(39, 174, 96, 255)' hexToRGB('27ae60'); // 'rgb(39, 174, 96)' hexToRGB('#fff'); // 'rgb(255, 255, 255)' -``` +``` \ No newline at end of file diff --git a/snippets/hide.md b/snippets/hide.md index 53e157adb..13faeefeb 100644 --- a/snippets/hide.md +++ b/snippets/hide.md @@ -1,4 +1,7 @@ -### hide +--- +title: hide +tags: browser,css,beginner +--- Hides all the elements specified. @@ -10,4 +13,4 @@ const hide = (...el) => [...el].forEach(e => (e.style.display = 'none')); ```js hide(document.querySelectorAll('img')); // Hides all elements on the page -``` +``` \ No newline at end of file diff --git a/snippets/httpGet.md b/snippets/httpGet.md index 73e2035b2..00feccc64 100644 --- a/snippets/httpGet.md +++ b/snippets/httpGet.md @@ -1,4 +1,7 @@ -### httpGet +--- +title: httpGet +tags: utility,url,browser,intermediate +--- Makes a `GET` request to the passed URL. @@ -29,4 +32,4 @@ Logs: { "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" } */ -``` +``` \ No newline at end of file diff --git a/snippets/httpPost.md b/snippets/httpPost.md index 8328d07fc..1522a3c41 100644 --- a/snippets/httpPost.md +++ b/snippets/httpPost.md @@ -1,4 +1,7 @@ -### httpPost +--- +title: httpPost +tags: utility,url,browser,intermediate +--- Makes a `POST` request to the passed URL. @@ -49,4 +52,4 @@ Logs: { "id": 101 } */ -``` +``` \ No newline at end of file diff --git a/snippets/httpsRedirect.md b/snippets/httpsRedirect.md index 6f91de045..6d47313a5 100644 --- a/snippets/httpsRedirect.md +++ b/snippets/httpsRedirect.md @@ -1,4 +1,7 @@ -### httpsRedirect +--- +title: httpsRedirect +tags: browser,url,intermediate +--- Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history. @@ -12,4 +15,4 @@ const httpsRedirect = () => { ```js httpsRedirect(); // If you are on http://mydomain.com, you are redirected to https://mydomain.com -``` +``` \ No newline at end of file diff --git a/snippets/hz.md b/snippets/hz.md index c1e9c0ceb..6ecef835b 100644 --- a/snippets/hz.md +++ b/snippets/hz.md @@ -1,4 +1,7 @@ -### hz +--- +title: hz +tags: function,intermediate +--- 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. @@ -32,4 +35,4 @@ const sumForLoop = () => { // `sumForLoop` is nearly 10 times faster Math.round(hz(sumReduce)); // 572 Math.round(hz(sumForLoop)); // 4784 -``` +``` \ No newline at end of file diff --git a/snippets/inRange.md b/snippets/inRange.md index 1f39394af..f3e324024 100644 --- a/snippets/inRange.md +++ b/snippets/inRange.md @@ -1,4 +1,7 @@ -### inRange +--- +title: inRange +tags: math,beginner +--- Checks if the given number falls within the given range. @@ -17,4 +20,4 @@ inRange(3, 2, 5); // true inRange(3, 4); // true inRange(2, 3, 5); // false inRange(3, 2); // false -``` +``` \ No newline at end of file diff --git a/snippets/indentString.md b/snippets/indentString.md index 4f716882c..06380c995 100644 --- a/snippets/indentString.md +++ b/snippets/indentString.md @@ -1,4 +1,7 @@ -### indentString +--- +title: indentString +tags: string,utility,beginner +--- Indents each line in the provided string. @@ -12,4 +15,4 @@ const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.rep ```js indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum' indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum' -``` +``` \ No newline at end of file diff --git a/snippets/indexOfAll.md b/snippets/indexOfAll.md index 237e62ca8..a3b82a8bb 100644 --- a/snippets/indexOfAll.md +++ b/snippets/indexOfAll.md @@ -1,4 +1,7 @@ -### indexOfAll +--- +title: indexOfAll +tags: array,intermediate +--- Returns all indices of `val` in an array. If `val` never occurs, returns `[]`. @@ -13,4 +16,4 @@ const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...ac ```js indexOfAll([1, 2, 3, 1, 2, 3], 1); // [0,3] indexOfAll([1, 2, 3], 4); // [] -``` +``` \ No newline at end of file diff --git a/snippets/initial.md b/snippets/initial.md index 2160b73b3..40703dec7 100644 --- a/snippets/initial.md +++ b/snippets/initial.md @@ -1,4 +1,7 @@ -### initial +--- +title: initial +tags: array,beginner +--- Returns all the elements of an array except the last one. @@ -10,4 +13,4 @@ const initial = arr => arr.slice(0, -1); ```js initial([1, 2, 3]); // [1,2] -``` +``` \ No newline at end of file diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md index 75f23fca6..05316ff3c 100644 --- a/snippets/initialize2DArray.md +++ b/snippets/initialize2DArray.md @@ -1,4 +1,7 @@ -### initialize2DArray +--- +title: initialize2DArray +tags: array,intermediate +--- Initializes a 2D array of given width and height and value. @@ -11,4 +14,4 @@ const initialize2DArray = (w, h, val = null) => ```js initialize2DArray(2, 2, 0); // [[0,0], [0,0]] -``` +``` \ No newline at end of file diff --git a/snippets/initializeArrayWithRange.md b/snippets/initializeArrayWithRange.md index 4cac19380..c07e4d98f 100644 --- a/snippets/initializeArrayWithRange.md +++ b/snippets/initializeArrayWithRange.md @@ -1,4 +1,7 @@ -### initializeArrayWithRange +--- +title: initializeArrayWithRange +tags: array,math,intermediate +--- Initializes an array containing the numbers in the specified range where `start` and `end` are inclusive with their common difference `step`. @@ -15,4 +18,4 @@ const initializeArrayWithRange = (end, start = 0, step = 1) => initializeArrayWithRange(5); // [0,1,2,3,4,5] initializeArrayWithRange(7, 3); // [3,4,5,6,7] initializeArrayWithRange(9, 0, 2); // [0,2,4,6,8] -``` +``` \ No newline at end of file diff --git a/snippets/initializeArrayWithRangeRight.md b/snippets/initializeArrayWithRangeRight.md index 6f9658f25..a4cb726ec 100644 --- a/snippets/initializeArrayWithRangeRight.md +++ b/snippets/initializeArrayWithRangeRight.md @@ -1,4 +1,7 @@ -### initializeArrayWithRangeRight +--- +title: initializeArrayWithRangeRight +tags: array,math,intermediate +--- Initializes an array containing the numbers in the specified range (in reverse) where `start` and `end` are inclusive with their common difference `step`. @@ -17,4 +20,4 @@ const initializeArrayWithRangeRight = (end, start = 0, step = 1) => initializeArrayWithRangeRight(5); // [5,4,3,2,1,0] initializeArrayWithRangeRight(7, 3); // [7,6,5,4,3] initializeArrayWithRangeRight(9, 0, 2); // [8,6,4,2,0] -``` +``` \ No newline at end of file diff --git a/snippets/initializeArrayWithValues.md b/snippets/initializeArrayWithValues.md index 56954ec53..b8a5535c4 100644 --- a/snippets/initializeArrayWithValues.md +++ b/snippets/initializeArrayWithValues.md @@ -1,4 +1,7 @@ -### initializeArrayWithValues +--- +title: initializeArrayWithValues +tags: array,math,intermediate +--- Initializes and fills an array with the specified values. @@ -11,4 +14,4 @@ const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val); ```js initializeArrayWithValues(5, 2); // [2, 2, 2, 2, 2] -``` +``` \ No newline at end of file diff --git a/snippets/initializeNDArray.md b/snippets/initializeNDArray.md index 868794f6b..2f5fb677b 100644 --- a/snippets/initializeNDArray.md +++ b/snippets/initializeNDArray.md @@ -1,4 +1,7 @@ -### initializeNDArray +--- +title: initializeNDArray +tags: array,recursion,intermediate +--- Create a n-dimensional array with given value. @@ -15,4 +18,4 @@ const initializeNDArray = (val, ...args) => ```js initializeNDArray(1, 3); // [1,1,1] initializeNDArray(5, 2, 2, 2); // [[[5,5],[5,5]],[[5,5],[5,5]]] -``` +``` \ No newline at end of file diff --git a/snippets/insertAfter.md b/snippets/insertAfter.md index e20c43037..7b105279a 100644 --- a/snippets/insertAfter.md +++ b/snippets/insertAfter.md @@ -1,4 +1,7 @@ -### insertAfter +--- +title: insertAfter +tags: browser,beginner +--- Inserts an HTML string after the end of the specified element. @@ -10,4 +13,4 @@ const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlSt ```js insertAfter(document.getElementById('myId'), '

    after

    '); //
    ...

    after

    -``` +``` \ No newline at end of file diff --git a/snippets/insertBefore.md b/snippets/insertBefore.md index 3891eb091..3a0f52f21 100644 --- a/snippets/insertBefore.md +++ b/snippets/insertBefore.md @@ -1,4 +1,7 @@ -### insertBefore +--- +title: insertBefore +tags: browser,beginner +--- Inserts an HTML string before the start of the specified element. @@ -10,4 +13,4 @@ const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', ht ```js insertBefore(document.getElementById('myId'), '

    before

    '); //

    before

    ...
    -``` +``` \ No newline at end of file diff --git a/snippets/intersection.md b/snippets/intersection.md index 6f86c57e9..76d55c677 100644 --- a/snippets/intersection.md +++ b/snippets/intersection.md @@ -1,4 +1,7 @@ -### intersection +--- +title: intersection +tags: array,math,intermediate +--- Returns a list of elements that exist in both arrays. @@ -13,4 +16,4 @@ const intersection = (a, b) => { ```js intersection([1, 2, 3], [4, 3, 2]); // [2, 3] -``` +``` \ No newline at end of file diff --git a/snippets/intersectionBy.md b/snippets/intersectionBy.md index 149a5226d..8c7d43390 100644 --- a/snippets/intersectionBy.md +++ b/snippets/intersectionBy.md @@ -1,4 +1,7 @@ -### intersectionBy +--- +title: intersectionBy +tags: array,function,intermediate +--- Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both. @@ -13,4 +16,4 @@ const intersectionBy = (a, b, fn) => { ```js intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1] -``` +``` \ No newline at end of file diff --git a/snippets/intersectionWith.md b/snippets/intersectionWith.md index b37487d11..06902ceba 100644 --- a/snippets/intersectionWith.md +++ b/snippets/intersectionWith.md @@ -1,4 +1,7 @@ -### intersectionWith +--- +title: intersectionWith +tags: array,function,intermediate +--- Returns a list of elements that exist in both arrays, using a provided comparator function. @@ -10,4 +13,4 @@ const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, ```js intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0] -``` +``` \ No newline at end of file diff --git a/snippets/invertKeyValues.md b/snippets/invertKeyValues.md index fc829eeee..36d24213c 100644 --- a/snippets/invertKeyValues.md +++ b/snippets/invertKeyValues.md @@ -1,4 +1,7 @@ -### invertKeyValues +--- +title: invertKeyValues +tags: object,function,intermediate +--- 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. @@ -18,4 +21,4 @@ const invertKeyValues = (obj, fn) => ```js invertKeyValues({ a: 1, b: 2, c: 1 }); // { 1: [ 'a', 'c' ], 2: [ 'b' ] } invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value); // { group1: [ 'a', 'c' ], group2: [ 'b' ] } -``` +``` \ No newline at end of file diff --git a/snippets/is.md b/snippets/is.md index 47b9782ab..3d09f239a 100644 --- a/snippets/is.md +++ b/snippets/is.md @@ -1,4 +1,7 @@ -### is +--- +title: is +tags: type,array,regexp,beginner +--- Checks if the provided value is of the specified type. @@ -22,4 +25,4 @@ is(Number, 1); // true is(Number, new Number(1)); // true is(Boolean, true); // true is(Boolean, new Boolean(true)); // true -``` +``` \ No newline at end of file diff --git a/snippets/isAbsoluteURL.md b/snippets/isAbsoluteURL.md index 00d8d8936..127aaf18f 100644 --- a/snippets/isAbsoluteURL.md +++ b/snippets/isAbsoluteURL.md @@ -1,4 +1,7 @@ -### isAbsoluteURL +--- +title: isAbsoluteURL +tags: string,utility,browser,url,intermediate +--- Returns `true` if the given string is an absolute URL, `false` otherwise. @@ -12,4 +15,4 @@ const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str); isAbsoluteURL('https://google.com'); // true isAbsoluteURL('ftp://www.myserver.net'); // true isAbsoluteURL('/foo/bar'); // false -``` +``` \ No newline at end of file diff --git a/snippets/isAfterDate.md b/snippets/isAfterDate.md index 02bdc9789..75d1ce350 100644 --- a/snippets/isAfterDate.md +++ b/snippets/isAfterDate.md @@ -1,4 +1,7 @@ -### isAfterDate +--- +title: isAfterDate +tags: date,utility,beginner +--- Check if a date is after another date. @@ -10,4 +13,4 @@ const isAfterDate = (dateA, dateB) => dateA > dateB; ```js isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true -``` +``` \ No newline at end of file diff --git a/snippets/isAnagram.md b/snippets/isAnagram.md index dd5755f63..c7fdceccd 100644 --- a/snippets/isAnagram.md +++ b/snippets/isAnagram.md @@ -1,4 +1,7 @@ -### isAnagram +--- +title: isAnagram +tags: string,regexp,intermediate +--- Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). @@ -19,4 +22,4 @@ const isAnagram = (str1, str2) => { ```js isAnagram('iceman', 'cinema'); // true -``` +``` \ No newline at end of file diff --git a/snippets/isArrayLike.md b/snippets/isArrayLike.md index 088ab4e52..2fe61e0f7 100644 --- a/snippets/isArrayLike.md +++ b/snippets/isArrayLike.md @@ -1,4 +1,7 @@ -### isArrayLike +--- +title: isArrayLike +tags: type,array,intermediate +--- Checks if the provided argument is array-like (i.e. is iterable). @@ -12,4 +15,4 @@ const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'funct isArrayLike(document.querySelectorAll('.className')); // true isArrayLike('abc'); // true isArrayLike(null); // false -``` +``` \ No newline at end of file diff --git a/snippets/isBeforeDate.md b/snippets/isBeforeDate.md index 3c0d2c2af..b2ebd41c6 100644 --- a/snippets/isBeforeDate.md +++ b/snippets/isBeforeDate.md @@ -1,4 +1,7 @@ -### isBeforeDate +--- +title: isBeforeDate +tags: date,utility,beginner +--- Check if a date is before another date. @@ -10,4 +13,4 @@ const isBeforeDate = (dateA, dateB) => dateA < dateB; ```js isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true -``` +``` \ No newline at end of file diff --git a/snippets/isBoolean.md b/snippets/isBoolean.md index 68a7effcf..4e7103eaf 100644 --- a/snippets/isBoolean.md +++ b/snippets/isBoolean.md @@ -1,4 +1,7 @@ -### isBoolean +--- +title: isBoolean +tags: type,beginner +--- Checks if the given argument is a native boolean element. @@ -11,4 +14,4 @@ const isBoolean = val => typeof val === 'boolean'; ```js isBoolean(null); // false isBoolean(false); // true -``` +``` \ No newline at end of file diff --git a/snippets/isBrowser.md b/snippets/isBrowser.md index 19264853c..0226ea600 100644 --- a/snippets/isBrowser.md +++ b/snippets/isBrowser.md @@ -1,4 +1,7 @@ -### isBrowser +--- +title: isBrowser +tags: utility,browser,intermediate +--- Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors. @@ -13,4 +16,4 @@ const isBrowser = () => ![typeof window, typeof document].includes('undefined'); ```js isBrowser(); // true (browser) isBrowser(); // false (Node) -``` +``` \ No newline at end of file diff --git a/snippets/isBrowserTabFocused.md b/snippets/isBrowserTabFocused.md index 3757a8257..ea8590b3b 100644 --- a/snippets/isBrowserTabFocused.md +++ b/snippets/isBrowserTabFocused.md @@ -1,4 +1,7 @@ -### isBrowserTabFocused +--- +title: isBrowserTabFocused +tags: browser,beginner +--- Returns `true` if the browser tab of the page is focused, `false` otherwise. @@ -10,4 +13,4 @@ const isBrowserTabFocused = () => !document.hidden; ```js isBrowserTabFocused(); // true -``` +``` \ No newline at end of file diff --git a/snippets/isDivisible.md b/snippets/isDivisible.md index d2e4987d0..a601089ae 100644 --- a/snippets/isDivisible.md +++ b/snippets/isDivisible.md @@ -1,4 +1,7 @@ -### isDivisible +--- +title: isDivisible +tags: math,beginner +--- Checks if the first numeric argument is divisible by the second one. @@ -10,4 +13,4 @@ const isDivisible = (dividend, divisor) => dividend % divisor === 0; ```js isDivisible(6, 3); // true -``` +``` \ No newline at end of file diff --git a/snippets/isDuplexStream.md b/snippets/isDuplexStream.md index dce0ab19f..bbb93e66a 100644 --- a/snippets/isDuplexStream.md +++ b/snippets/isDuplexStream.md @@ -1,4 +1,7 @@ -### isDuplexStream +--- +title: isDuplexStream +tags: node,type,intermediate +--- Checks if the given argument is a duplex (readable and writable) stream. @@ -19,4 +22,4 @@ const isDuplexStream = val => ```js const Stream = require('stream'); isDuplexStream(new Stream.Duplex()); // true -``` +``` \ No newline at end of file diff --git a/snippets/isEmpty.md b/snippets/isEmpty.md index 5dcd23708..3246d2424 100644 --- a/snippets/isEmpty.md +++ b/snippets/isEmpty.md @@ -1,4 +1,7 @@ -### isEmpty +--- +title: isEmpty +tags: type,array,object,string,beginner +--- Returns true if the a value is an empty object, collection, has no enumerable properties or is any type that is not considered a collection. @@ -17,4 +20,4 @@ isEmpty({ a: 1, b: 2 }); // false isEmpty('text'); // false isEmpty(123); // true - type is not considered a collection isEmpty(true); // true - type is not considered a collection -``` +``` \ No newline at end of file diff --git a/snippets/isEven.md b/snippets/isEven.md index 52e0b635c..843022c75 100644 --- a/snippets/isEven.md +++ b/snippets/isEven.md @@ -1,4 +1,7 @@ -### isEven +--- +title: isEven +tags: math,beginner +--- Returns `true` if the given number is even, `false` otherwise. @@ -11,4 +14,4 @@ const isEven = num => num % 2 === 0; ```js isEven(3); // false -``` +``` \ No newline at end of file diff --git a/snippets/isFunction.md b/snippets/isFunction.md index 0cf8ee580..41d9e8b0f 100644 --- a/snippets/isFunction.md +++ b/snippets/isFunction.md @@ -1,4 +1,7 @@ -### isFunction +--- +title: isFunction +tags: type,function,beginner +--- Checks if the given argument is a function. @@ -11,4 +14,4 @@ const isFunction = val => typeof val === 'function'; ```js isFunction('x'); // false isFunction(x => x); // true -``` +``` \ No newline at end of file diff --git a/snippets/isLowerCase.md b/snippets/isLowerCase.md index 602bdc427..7be7b4a7d 100644 --- a/snippets/isLowerCase.md +++ b/snippets/isLowerCase.md @@ -1,4 +1,7 @@ -### isLowerCase +--- +title: isLowerCase +tags: string,utility,beginner +--- Checks if a string is lower case. @@ -12,4 +15,4 @@ const isLowerCase = str => str === str.toLowerCase(); isLowerCase('abc'); // true isLowerCase('a3@$'); // true isLowerCase('Ab4'); // false -``` +``` \ No newline at end of file diff --git a/snippets/isNegativeZero.md b/snippets/isNegativeZero.md index 3ad3bca8a..065c1a01d 100644 --- a/snippets/isNegativeZero.md +++ b/snippets/isNegativeZero.md @@ -1,4 +1,7 @@ -### isNegativeZero +--- +title: isNegativeZero +tags: math,utility,beginner +--- Checks if the given value is equal to negative zero (`-0`). @@ -11,4 +14,4 @@ const isNegativeZero = val => val === 0 && 1 / val === -Infinity; ```js isNegativeZero(-0); // true isNegativeZero(0); // false -``` +``` \ No newline at end of file diff --git a/snippets/isNil.md b/snippets/isNil.md index 82618c36f..c8ed1cbb2 100644 --- a/snippets/isNil.md +++ b/snippets/isNil.md @@ -1,4 +1,7 @@ -### isNil +--- +title: isNil +tags: type,beginner +--- Returns `true` if the specified value is `null` or `undefined`, `false` otherwise. @@ -11,4 +14,4 @@ const isNil = val => val === undefined || val === null; ```js isNil(null); // true isNil(undefined); // true -``` +``` \ No newline at end of file diff --git a/snippets/isNull.md b/snippets/isNull.md index e0b5de1bf..ba9495124 100644 --- a/snippets/isNull.md +++ b/snippets/isNull.md @@ -1,4 +1,7 @@ -### isNull +--- +title: isNull +tags: type,beginner +--- Returns `true` if the specified value is `null`, `false` otherwise. @@ -10,4 +13,4 @@ const isNull = val => val === null; ```js isNull(null); // true -``` +``` \ No newline at end of file diff --git a/snippets/isNumber.md b/snippets/isNumber.md index ff0bfe9b9..fbe8dda15 100644 --- a/snippets/isNumber.md +++ b/snippets/isNumber.md @@ -1,4 +1,7 @@ -### isNumber +--- +title: isNumber +tags: type,math,beginner +--- Checks if the given argument is a number. @@ -13,4 +16,4 @@ const isNumber = val => typeof val === 'number' && val === val; isNumber(1); // true isNumber('1'); // false isNumber(NaN); // false -``` +``` \ No newline at end of file diff --git a/snippets/isObject.md b/snippets/isObject.md index eb8aee625..25aa2c5d1 100644 --- a/snippets/isObject.md +++ b/snippets/isObject.md @@ -1,4 +1,7 @@ -### isObject +--- +title: isObject +tags: type,object,beginner +--- Returns a boolean determining if the passed value is an object or not. @@ -16,4 +19,4 @@ isObject(['Hello!']); // true isObject({ a: 1 }); // true isObject({}); // true isObject(true); // false -``` +``` \ No newline at end of file diff --git a/snippets/isObjectLike.md b/snippets/isObjectLike.md index 969fdecd4..44109d604 100644 --- a/snippets/isObjectLike.md +++ b/snippets/isObjectLike.md @@ -1,4 +1,7 @@ -### isObjectLike +--- +title: isObjectLike +tags: type,object,beginner +--- Checks if a value is object-like. @@ -13,4 +16,4 @@ isObjectLike({}); // true isObjectLike([1, 2, 3]); // true isObjectLike(x => x); // false isObjectLike(null); // false -``` +``` \ No newline at end of file diff --git a/snippets/isPlainObject.md b/snippets/isPlainObject.md index 8ee65ae11..f824de94b 100644 --- a/snippets/isPlainObject.md +++ b/snippets/isPlainObject.md @@ -1,4 +1,7 @@ -### isPlainObject +--- +title: isPlainObject +tags: type,object,intermediate +--- Checks if the provided value is an object created by the Object constructor. @@ -11,4 +14,4 @@ const isPlainObject = val => !!val && typeof val === 'object' && val.constructor ```js isPlainObject({ a: 1 }); // true isPlainObject(new Map()); // false -``` +``` \ No newline at end of file diff --git a/snippets/isPrime.md b/snippets/isPrime.md index 0b09bda15..ac150727c 100644 --- a/snippets/isPrime.md +++ b/snippets/isPrime.md @@ -1,4 +1,7 @@ -### isPrime +--- +title: isPrime +tags: math,beginner,intermediate +--- Checks if the provided integer is a prime number. @@ -15,4 +18,4 @@ const isPrime = num => { ```js isPrime(11); // true -``` +``` \ No newline at end of file diff --git a/snippets/isPrimitive.md b/snippets/isPrimitive.md index 9f2550e01..1840f8d95 100644 --- a/snippets/isPrimitive.md +++ b/snippets/isPrimitive.md @@ -1,4 +1,7 @@ -### isPrimitive +--- +title: isPrimitive +tags: type,function,array,string,intermediate +--- Returns a boolean determining if the passed value is primitive or not. @@ -15,4 +18,4 @@ isPrimitive('Hello!'); // true isPrimitive(false); // true isPrimitive(Symbol()); // true isPrimitive([]); // false -``` +``` \ No newline at end of file diff --git a/snippets/isPromiseLike.md b/snippets/isPromiseLike.md index 6a2ae29d4..707234290 100644 --- a/snippets/isPromiseLike.md +++ b/snippets/isPromiseLike.md @@ -1,4 +1,7 @@ -### isPromiseLike +--- +title: isPromiseLike +tags: type,function,promise,intermediate +--- Returns `true` if an object looks like a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), `false` otherwise. @@ -19,4 +22,4 @@ isPromiseLike({ }); // true isPromiseLike(null); // false isPromiseLike({}); // false -``` +``` \ No newline at end of file diff --git a/snippets/isReadableStream.md b/snippets/isReadableStream.md index 3ac9701eb..0cb957ed5 100644 --- a/snippets/isReadableStream.md +++ b/snippets/isReadableStream.md @@ -1,4 +1,7 @@ -### isReadableStream +--- +title: isReadableStream +tags: node,type,intermediate +--- Checks if the given argument is a readable stream. @@ -17,4 +20,4 @@ const isReadableStream = val => ```js const fs = require('fs'); isReadableStream(fs.createReadStream('test.txt')); // true -``` +``` \ No newline at end of file diff --git a/snippets/isSameDate.md b/snippets/isSameDate.md index 5e30edf4d..8447317c2 100644 --- a/snippets/isSameDate.md +++ b/snippets/isSameDate.md @@ -1,4 +1,7 @@ -### isSameDate +--- +title: isSameDate +tags: date,utility,beginner +--- Check if a date is the same as another date. @@ -10,4 +13,4 @@ const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString() ```js isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true -``` +``` \ No newline at end of file diff --git a/snippets/isSorted.md b/snippets/isSorted.md index b5ece6291..fc29d3810 100644 --- a/snippets/isSorted.md +++ b/snippets/isSorted.md @@ -1,4 +1,7 @@ -### isSorted +--- +title: isSorted +tags: array,intermediate +--- Returns `1` if the array is sorted in ascending order, `-1` if it is sorted in descending order or `0` if it is not sorted. @@ -21,4 +24,4 @@ const isSorted = arr => { isSorted([0, 1, 2, 2]); // 1 isSorted([4, 3, 2]); // -1 isSorted([4, 3, 5]); // 0 -``` +``` \ No newline at end of file diff --git a/snippets/isStream.md b/snippets/isStream.md index 6cb83a703..5bcfe49a5 100644 --- a/snippets/isStream.md +++ b/snippets/isStream.md @@ -1,4 +1,7 @@ -### isStream +--- +title: isStream +tags: node,type,intermediate +--- Checks if the given argument is a stream. @@ -11,4 +14,4 @@ const isStream = val => val !== null && typeof val === 'object' && typeof val.pi ```js const fs = require('fs'); isStream(fs.createReadStream('test.txt')); // true -``` +``` \ No newline at end of file diff --git a/snippets/isString.md b/snippets/isString.md index 3b8ae9f88..cb6d44230 100644 --- a/snippets/isString.md +++ b/snippets/isString.md @@ -1,4 +1,7 @@ -### isString +--- +title: isString +tags: type,string,beginner +--- Checks if the given argument is a string. Only works for string primitives. @@ -10,4 +13,4 @@ const isString = val => typeof val === 'string'; ```js isString('10'); // true -``` +``` \ No newline at end of file diff --git a/snippets/isSymbol.md b/snippets/isSymbol.md index d4602276f..71813107f 100644 --- a/snippets/isSymbol.md +++ b/snippets/isSymbol.md @@ -1,4 +1,7 @@ -### isSymbol +--- +title: isSymbol +tags: type,beginner +--- Checks if the given argument is a symbol. @@ -10,4 +13,4 @@ const isSymbol = val => typeof val === 'symbol'; ```js isSymbol(Symbol('x')); // true -``` +``` \ No newline at end of file diff --git a/snippets/isTravisCI.md b/snippets/isTravisCI.md index 6b7d6d889..85c4d03de 100644 --- a/snippets/isTravisCI.md +++ b/snippets/isTravisCI.md @@ -1,4 +1,7 @@ -### isTravisCI +--- +title: isTravisCI +tags: node,intermediate +--- Checks if the current environment is [Travis CI](https://travis-ci.org/). @@ -10,4 +13,4 @@ const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; ```js isTravisCI(); // true (if code is running on Travis CI) -``` +``` \ No newline at end of file diff --git a/snippets/isUndefined.md b/snippets/isUndefined.md index 265b80e57..d6e09916b 100644 --- a/snippets/isUndefined.md +++ b/snippets/isUndefined.md @@ -1,4 +1,7 @@ -### isUndefined +--- +title: isUndefined +tags: type,beginner +--- Returns `true` if the specified value is `undefined`, `false` otherwise. @@ -10,4 +13,4 @@ const isUndefined = val => val === undefined; ```js isUndefined(undefined); // true -``` +``` \ No newline at end of file diff --git a/snippets/isUpperCase.md b/snippets/isUpperCase.md index 0fc69f254..314bde5d7 100644 --- a/snippets/isUpperCase.md +++ b/snippets/isUpperCase.md @@ -1,10 +1,12 @@ -### isUpperCase +--- +title: isUpperCase +tags: string,utility,beginner +--- Checks if a string is upper case. Convert the given string to upper case, using `String.prototype.toUpperCase()` and compare it to the original. - ```js const isUpperCase = str => str === str.toUpperCase(); ``` @@ -13,4 +15,4 @@ const isUpperCase = str => str === str.toUpperCase(); isUpperCase('ABC'); // true isLowerCase('A3@$'); // true isLowerCase('aB4'); // false -``` +``` \ No newline at end of file diff --git a/snippets/isValidJSON.md b/snippets/isValidJSON.md index 3ad0f98d5..ced4d9066 100644 --- a/snippets/isValidJSON.md +++ b/snippets/isValidJSON.md @@ -1,4 +1,7 @@ -### isValidJSON +--- +title: isValidJSON +tags: type,json,intermediate +--- Checks if the provided string is a valid JSON. @@ -19,4 +22,4 @@ const isValidJSON = str => { isValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam",age:"20"}'); // false isValidJSON(null); // true -``` +``` \ No newline at end of file diff --git a/snippets/isWeekday.md b/snippets/isWeekday.md index 8a56323bc..48a58dc2e 100644 --- a/snippets/isWeekday.md +++ b/snippets/isWeekday.md @@ -1,4 +1,7 @@ -### isWeekday +--- +title: isWeekday +tags: date,beginner +--- Results in a boolean representation of a specific date. @@ -13,4 +16,4 @@ const isWeekday = (t = new Date()) => { ```js isWeekday(); // true (if current date is 2019-07-19) -``` +``` \ No newline at end of file diff --git a/snippets/isWeekend.md b/snippets/isWeekend.md index f3fb253b4..752d3c7bd 100644 --- a/snippets/isWeekend.md +++ b/snippets/isWeekend.md @@ -1,4 +1,7 @@ -### isWeekend +--- +title: isWeekend +tags: date,beginner +--- Results in a boolean representation of a specific date. @@ -13,4 +16,4 @@ const isWeekend = (t = new Date()) => { ```js isWeekend(); // 2018-10-19 (if current date is 2018-10-18) -``` +``` \ No newline at end of file diff --git a/snippets/isWritableStream.md b/snippets/isWritableStream.md index 8c30b8d2b..1c5749a46 100644 --- a/snippets/isWritableStream.md +++ b/snippets/isWritableStream.md @@ -1,4 +1,7 @@ -### isWritableStream +--- +title: isWritableStream +tags: node,type,intermediate +--- Checks if the given argument is a writable stream. @@ -17,4 +20,4 @@ const isWritableStream = val => ```js const fs = require('fs'); isWritableStream(fs.createWriteStream('test.txt')); // true -``` +``` \ No newline at end of file diff --git a/snippets/join.md b/snippets/join.md index db65278d6..89d1f7a72 100644 --- a/snippets/join.md +++ b/snippets/join.md @@ -1,4 +1,7 @@ -### join +--- +title: join +tags: array,intermediate +--- Joins all elements of an array into a string and returns this string. Uses a separator and an end separator. @@ -24,4 +27,4 @@ const join = (arr, separator = ',', end = separator) => 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" -``` +``` \ No newline at end of file diff --git a/snippets/last.md b/snippets/last.md index ee6ab47a6..9b713d98d 100644 --- a/snippets/last.md +++ b/snippets/last.md @@ -1,4 +1,7 @@ -### last +--- +title: last +tags: array,beginner +--- Returns the last element in an array. @@ -10,4 +13,4 @@ const last = arr => arr[arr.length - 1]; ```js last([1, 2, 3]); // 3 -``` +``` \ No newline at end of file diff --git a/snippets/lcm.md b/snippets/lcm.md index 970e3083c..322bb4d8d 100644 --- a/snippets/lcm.md +++ b/snippets/lcm.md @@ -1,4 +1,7 @@ -### lcm +--- +title: lcm +tags: math,recursion,beginner +--- Returns the least common multiple of two or more numbers. @@ -16,4 +19,4 @@ const lcm = (...arr) => { ```js lcm(12, 7); // 84 lcm(...[1, 3, 4, 5]); // 60 -``` +``` \ No newline at end of file diff --git a/snippets/longestItem.md b/snippets/longestItem.md index c1c72e2d6..918865ee4 100644 --- a/snippets/longestItem.md +++ b/snippets/longestItem.md @@ -1,4 +1,7 @@ -### longestItem +--- +title: longestItem +tags: array,string,utility,intermediate +--- Takes any number of iterable objects or objects with a `length` property and returns the longest one. If multiple objects have the same length, the first one will be returned. @@ -16,4 +19,4 @@ longestItem(...['a', 'ab', 'abc']); // 'abc' longestItem(...['a', 'ab', 'abc'], 'abcd'); // 'abcd' longestItem([1, 2, 3], [1, 2], [1, 2, 3, 4, 5]); // [1, 2, 3, 4, 5] longestItem([1, 2, 3], 'foobar'); // 'foobar' -``` +``` \ No newline at end of file diff --git a/snippets/lowercaseKeys.md b/snippets/lowercaseKeys.md index 9c5a8b551..ee0e16376 100644 --- a/snippets/lowercaseKeys.md +++ b/snippets/lowercaseKeys.md @@ -1,4 +1,7 @@ -### lowercaseKeys +--- +title: lowercaseKeys +tags: object,intermediate +--- Creates a new object from the specified object, where all the keys are in lowercase. @@ -16,4 +19,4 @@ const lowercaseKeys = obj => ```js const myObj = { Name: 'Adam', sUrnAME: 'Smith' }; const myObjLower = lowercaseKeys(myObj); // {name: 'Adam', surname: 'Smith'}; -``` +``` \ No newline at end of file diff --git a/snippets/luhnCheck.md b/snippets/luhnCheck.md index c99532ed1..797a204ba 100644 --- a/snippets/luhnCheck.md +++ b/snippets/luhnCheck.md @@ -1,4 +1,7 @@ -### luhnCheck +--- +title: luhnCheck +tags: math,utility,advanced +--- Implementation of the [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc. @@ -7,7 +10,6 @@ Use `Array.prototype.splice(0,1)` to obtain the last digit. Use `Array.prototype.reduce()` to implement the Luhn Algorithm. Return `true` if `sum` is divisible by `10`, `false` otherwise. - ```js const luhnCheck = num => { let arr = (num + '') @@ -25,4 +27,4 @@ const luhnCheck = num => { luhnCheck('4485275742308327'); // true luhnCheck(6011329933655299); // false luhnCheck(123456789); // false -``` +``` \ No newline at end of file diff --git a/snippets/mapKeys.md b/snippets/mapKeys.md index cf26bf6d0..fcae17f3f 100644 --- a/snippets/mapKeys.md +++ b/snippets/mapKeys.md @@ -1,4 +1,7 @@ -### mapKeys +--- +title: mapKeys +tags: object,function,intermediate +--- Creates an object with keys generated by running the provided function for each key and the same values as the provided object. @@ -15,4 +18,4 @@ const mapKeys = (obj, fn) => ```js mapKeys({ a: 1, b: 2 }, (val, key) => key + val); // { a1: 1, b2: 2 } -``` +``` \ No newline at end of file diff --git a/snippets/mapNumRange.md b/snippets/mapNumRange.md index c007f433f..445764835 100644 --- a/snippets/mapNumRange.md +++ b/snippets/mapNumRange.md @@ -1,4 +1,7 @@ -### mapNumRange +--- +title: mapNumRange +tags: math,beginner +--- Maps a number from one range to another range. @@ -11,4 +14,4 @@ const mapNumRange = (num, inMin, inMax, outMin, outMax) => ```js mapNumRange(5, 0, 10, 0, 100); // 50 -``` +``` \ No newline at end of file diff --git a/snippets/mapObject.md b/snippets/mapObject.md index c60dbdbec..04130214f 100644 --- a/snippets/mapObject.md +++ b/snippets/mapObject.md @@ -1,4 +1,7 @@ -### mapObject +--- +title: mapObject +tags: array,object,advanced +--- Maps the values of an array to an object using a function, where the key-value pairs consist of the stringified value as the key and the mapped value. @@ -14,4 +17,4 @@ const mapObject = (arr, fn) => ```js const squareIt = arr => mapObject(arr, a => a * a); squareIt([1, 2, 3]); // { 1: 1, 2: 4, 3: 9 } -``` +``` \ No newline at end of file diff --git a/snippets/mapString.md b/snippets/mapString.md index d47375ca2..8140a5b28 100644 --- a/snippets/mapString.md +++ b/snippets/mapString.md @@ -1,4 +1,7 @@ -### mapString +--- +title: mapString +tags: string,array,function,utility,beginner +--- Creates a new string with the results of calling a provided function on every character in the calling string. @@ -16,4 +19,4 @@ const mapString = (str, fn) => ```js mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM' -``` +``` \ No newline at end of file diff --git a/snippets/mapValues.md b/snippets/mapValues.md index 976be96b6..88540a889 100644 --- a/snippets/mapValues.md +++ b/snippets/mapValues.md @@ -1,4 +1,7 @@ -### mapValues +--- +title: mapValues +tags: object,function,intermediate +--- Creates an object with the same keys as the provided object and values generated by running the provided function for each value. @@ -19,4 +22,4 @@ const users = { pebbles: { user: 'pebbles', age: 1 } }; mapValues(users, u => u.age); // { fred: 40, pebbles: 1 } -``` +``` \ No newline at end of file diff --git a/snippets/mask.md b/snippets/mask.md index 2024b2463..2456fc167 100644 --- a/snippets/mask.md +++ b/snippets/mask.md @@ -1,4 +1,7 @@ -### mask +--- +title: mask +tags: string,utility,regexp,intermediate +--- Replaces all but the last `num` of characters with the specified mask character. @@ -14,4 +17,4 @@ const mask = (cc, num = 4, mask = '*') => `${cc}`.slice(-num).padStart(`${cc}`.l mask(1234567890); // '******7890' mask(1234567890, 3); // '*******890' mask(1234567890, -4, '$'); // '$$$$567890' -``` +``` \ No newline at end of file diff --git a/snippets/matches.md b/snippets/matches.md index 0b82a3186..b1527ce04 100644 --- a/snippets/matches.md +++ b/snippets/matches.md @@ -1,4 +1,7 @@ -### matches +--- +title: matches +tags: object,type,intermediate +--- Compares two objects to determine if the first one contains equivalent property values to the second one. @@ -12,4 +15,4 @@ const matches = (obj, source) => ```js matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true }); // true matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true }); // false -``` +``` \ No newline at end of file diff --git a/snippets/matchesWith.md b/snippets/matchesWith.md index 1b4d730a1..fd32924fa 100644 --- a/snippets/matchesWith.md +++ b/snippets/matchesWith.md @@ -1,4 +1,7 @@ -### matchesWith +--- +title: matchesWith +tags: object,type,function,intermediate +--- Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function. @@ -22,4 +25,4 @@ matchesWith( { greeting: 'hi' }, (oV, sV) => isGreeting(oV) && isGreeting(sV) ); // true -``` +``` \ No newline at end of file diff --git a/snippets/maxBy.md b/snippets/maxBy.md index 2a5495ebf..8a34a4f9c 100644 --- a/snippets/maxBy.md +++ b/snippets/maxBy.md @@ -1,4 +1,7 @@ -### maxBy +--- +title: maxBy +tags: math,array,function,beginner +--- Returns the maximum value of an array, after mapping each element to a value using the provided function. @@ -11,4 +14,4 @@ const maxBy = (arr, fn) => Math.max(...arr.map(typeof fn === 'function' ? fn : v ```js maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8 maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 -``` +``` \ No newline at end of file diff --git a/snippets/maxDate.md b/snippets/maxDate.md index 4b66adb94..5b421a7a5 100644 --- a/snippets/maxDate.md +++ b/snippets/maxDate.md @@ -1,4 +1,7 @@ -### maxDate +--- +title: maxDate +tags: date,math,beginner +--- Returns the maximum of the given dates. @@ -16,4 +19,4 @@ const array = [ new Date(2016, 0, 9) ]; maxDate(array); // 2018-03-11T22:00:00.000Z -``` +``` \ No newline at end of file diff --git a/snippets/maxN.md b/snippets/maxN.md index d5d18d431..61b8e1cf7 100644 --- a/snippets/maxN.md +++ b/snippets/maxN.md @@ -1,4 +1,7 @@ -### maxN +--- +title: maxN +tags: array,math,beginner +--- 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). @@ -14,4 +17,4 @@ const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n); ```js maxN([1, 2, 3]); // [3] maxN([1, 2, 3], 2); // [3,2] -``` +``` \ No newline at end of file diff --git a/snippets/median.md b/snippets/median.md index 5463427f3..b754ffa5b 100644 --- a/snippets/median.md +++ b/snippets/median.md @@ -1,4 +1,7 @@ -### median +--- +title: median +tags: math,array,intermediate +--- Returns the median of an array of numbers. @@ -15,4 +18,4 @@ const median = arr => { ```js median([5, 6, 50, 1, -5]); // 5 -``` +``` \ No newline at end of file diff --git a/snippets/memoize.md b/snippets/memoize.md index 8d63b0e7f..aab793ab3 100644 --- a/snippets/memoize.md +++ b/snippets/memoize.md @@ -1,4 +1,7 @@ -### memoize +--- +title: memoize +tags: function,advanced +--- Returns the memoized (cached) function. @@ -23,4 +26,4 @@ const anagramsCached = memoize(anagrams); anagramsCached('javascript'); // takes a long time anagramsCached('javascript'); // returns virtually instantly since it's now cached console.log(anagramsCached.cache); // The cached anagrams map -``` +``` \ No newline at end of file diff --git a/snippets/merge.md b/snippets/merge.md index c9b4cf697..5dc7ec6a9 100644 --- a/snippets/merge.md +++ b/snippets/merge.md @@ -1,4 +1,7 @@ -### merge +--- +title: merge +tags: object,array,intermediate +--- Creates a new object from the combination of two or more objects. @@ -28,4 +31,4 @@ const other = { c: 'foo' }; merge(object, other); // { a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' } -``` +``` \ No newline at end of file diff --git a/snippets/midpoint.md b/snippets/midpoint.md index 05f5dcf8f..9c746536a 100644 --- a/snippets/midpoint.md +++ b/snippets/midpoint.md @@ -1,4 +1,7 @@ -### midpoint +--- +title: midpoint +tags: math,array,beginner +--- Calculates the midpoint between two pairs of (x,y) points. @@ -12,5 +15,4 @@ const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2]; midpoint([2, 2], [4, 4]); // [3, 3] midpoint([4, 4], [6, 6]); // [5, 5] midpoint([1, 3], [2, 4]); // [1.5, 3.5] -``` - +``` \ No newline at end of file diff --git a/snippets/minBy.md b/snippets/minBy.md index 6746cd943..43a85ff52 100644 --- a/snippets/minBy.md +++ b/snippets/minBy.md @@ -1,4 +1,7 @@ -### minBy +--- +title: minBy +tags: math,array,function,beginner +--- Returns the minimum value of an array, after mapping each element to a value using the provided function. @@ -11,4 +14,4 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v ```js minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2 minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2 -``` +``` \ No newline at end of file diff --git a/snippets/minDate.md b/snippets/minDate.md index 1c6b0eebc..e6a43d1f9 100644 --- a/snippets/minDate.md +++ b/snippets/minDate.md @@ -1,4 +1,7 @@ -### minDate +--- +title: minDate +tags: date,math,beginner +--- Returns the minimum of the given dates. @@ -16,4 +19,4 @@ const array = [ new Date(2016, 0, 9) ]; minDate(array); // 2016-01-08T22:00:00.000Z -``` +``` \ No newline at end of file diff --git a/snippets/minN.md b/snippets/minN.md index cfbac1fd9..3957ed934 100644 --- a/snippets/minN.md +++ b/snippets/minN.md @@ -1,4 +1,7 @@ -### minN +--- +title: minN +tags: array,math,beginner +--- Returns the `n` minimum 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 ascending order). @@ -10,7 +13,8 @@ Omit the second argument, `n`, to get a one-element array. ```js const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n); ``` + ```js minN([1, 2, 3]); // [1] minN([1, 2, 3], 2); // [1,2] -``` +``` \ No newline at end of file diff --git a/snippets/mostPerformant.md b/snippets/mostPerformant.md index cc2c6c876..a61be4063 100644 --- a/snippets/mostPerformant.md +++ b/snippets/mostPerformant.md @@ -1,4 +1,7 @@ -### mostPerformant +--- +title: mostPerformant +tags: utility,function +--- Returns the index of the function in an array of functions which executed the fastest. @@ -28,4 +31,4 @@ mostPerformant([ [1, '2', 3, 4, 5, 6, 7, 8, 9, 10].every(el => typeof el === 'number'); } ]); // 1 -``` +``` \ No newline at end of file diff --git a/snippets/negate.md b/snippets/negate.md index 3dd3843da..9012a6c4d 100644 --- a/snippets/negate.md +++ b/snippets/negate.md @@ -1,4 +1,7 @@ -### negate +--- +title: negate +tags: function,beginner +--- Negates a predicate function. @@ -10,4 +13,4 @@ const negate = func => (...args) => !func(...args); ```js [1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)); // [ 1, 3, 5 ] -``` +``` \ No newline at end of file diff --git a/snippets/nest.md b/snippets/nest.md index de57b03b3..56b5094fa 100644 --- a/snippets/nest.md +++ b/snippets/nest.md @@ -1,4 +1,7 @@ -### nest +--- +title: nest +tags: object,intermediate +--- Given a flat array of objects linked to one another, it will nest them recursively. Useful for nesting comments, such as the ones on reddit.com. @@ -25,5 +28,4 @@ const comments = [ { id: 5, parent_id: 4 } ]; const nestedComments = nest(comments); // [{ id: 1, parent_id: null, children: [...] }] -``` - +``` \ No newline at end of file diff --git a/snippets/nodeListToArray.md b/snippets/nodeListToArray.md index 1f41b0a76..7b7c1c142 100644 --- a/snippets/nodeListToArray.md +++ b/snippets/nodeListToArray.md @@ -1,4 +1,7 @@ -### nodeListToArray +--- +title: nodeListToArray +tags: browser,array,beginner +--- Converts a `NodeList` to an array. @@ -10,4 +13,4 @@ const nodeListToArray = nodeList => [...nodeList]; ```js nodeListToArray(document.childNodes); // [ , html ] -``` +``` \ No newline at end of file diff --git a/snippets/none.md b/snippets/none.md index 687c6f3e0..a6edb9735 100644 --- a/snippets/none.md +++ b/snippets/none.md @@ -1,4 +1,7 @@ -### none +--- +title: none +tags: array,function,beginner +--- Returns `true` if the provided predicate function returns `false` for all elements in a collection, `false` otherwise. @@ -12,4 +15,4 @@ const none = (arr, fn = Boolean) => !arr.some(fn); ```js none([0, 1, 3, 0], x => x == 2); // true none([0, 0, 0]); // true -``` +``` \ No newline at end of file diff --git a/snippets/nthArg.md b/snippets/nthArg.md index 5d0dad96a..53b25c3da 100644 --- a/snippets/nthArg.md +++ b/snippets/nthArg.md @@ -1,4 +1,7 @@ -### nthArg +--- +title: nthArg +tags: utility,function,beginner +--- Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned. @@ -14,4 +17,4 @@ third(1, 2, 3); // 3 third(1, 2); // undefined const last = nthArg(-1); last(1, 2, 3, 4, 5); // 5 -``` +``` \ No newline at end of file diff --git a/snippets/nthElement.md b/snippets/nthElement.md index 0e0064a41..33786ff7d 100644 --- a/snippets/nthElement.md +++ b/snippets/nthElement.md @@ -1,4 +1,7 @@ -### nthElement +--- +title: nthElement +tags: array,beginner +--- Returns the nth element of an array. @@ -13,4 +16,4 @@ const nthElement = (arr, n = 0) => (n === -1 ? arr.slice(n) : arr.slice(n, n + 1 ```js nthElement(['a', 'b', 'c'], 1); // 'b' nthElement(['a', 'b', 'b'], -3); // 'a' -``` +``` \ No newline at end of file diff --git a/snippets/objectFromPairs.md b/snippets/objectFromPairs.md index 4630f8aef..e715f2bc3 100644 --- a/snippets/objectFromPairs.md +++ b/snippets/objectFromPairs.md @@ -1,4 +1,7 @@ -### objectFromPairs +--- +title: objectFromPairs +tags: object,array,beginner +--- Creates an object from the given key-value pairs. @@ -10,4 +13,4 @@ const objectFromPairs = arr => arr.reduce((a, [key, val]) => ((a[key] = val), a) ```js objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2} -``` +``` \ No newline at end of file diff --git a/snippets/objectToPairs.md b/snippets/objectToPairs.md index d91040d3d..9e241a96e 100644 --- a/snippets/objectToPairs.md +++ b/snippets/objectToPairs.md @@ -1,4 +1,7 @@ -### objectToPairs +--- +title: objectToPairs +tags: object,array,beginner +--- Creates an array of key-value pair arrays from an object. @@ -10,4 +13,4 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]); ```js objectToPairs({ a: 1, b: 2 }); // [ ['a', 1], ['b', 2] ] -``` +``` \ No newline at end of file diff --git a/snippets/observeMutations.md b/snippets/observeMutations.md index d62851102..d8bd7a4ef 100644 --- a/snippets/observeMutations.md +++ b/snippets/observeMutations.md @@ -1,4 +1,7 @@ -### observeMutations +--- +title: observeMutations +tags: browser,event,advanced +--- Returns a new MutationObserver and runs the provided callback for each mutation on the specified element. @@ -30,4 +33,4 @@ const observeMutations = (element, callback, options) => { ```js const obs = observeMutations(document, console.log); // Logs all mutations that happen on the page obs.disconnect(); // Disconnects the observer and stops logging mutations on the page -``` +``` \ No newline at end of file diff --git a/snippets/off.md b/snippets/off.md index 726dca29e..613be95e1 100644 --- a/snippets/off.md +++ b/snippets/off.md @@ -1,4 +1,7 @@ -### off +--- +title: off +tags: browser,event,intermediate +--- Removes an event listener from an element. @@ -13,4 +16,4 @@ const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts) const fn = () => console.log('!'); document.body.addEventListener('click', fn); off(document.body, 'click', fn); // no longer logs '!' upon clicking on the page -``` +``` \ No newline at end of file diff --git a/snippets/offset.md b/snippets/offset.md index 5b2835fc7..1fdac50d5 100644 --- a/snippets/offset.md +++ b/snippets/offset.md @@ -1,4 +1,7 @@ -### offset +--- +title: offset +tags: array,beginner +--- Moves the specified amount of elements to the end of the array. @@ -13,4 +16,4 @@ const offset = (arr, offset) => [...arr.slice(offset), ...arr.slice(0, offset)]; ```js offset([1, 2, 3, 4, 5], 2); // [3, 4, 5, 1, 2] offset([1, 2, 3, 4, 5], -2); // [4, 5, 1, 2, 3] -``` +``` \ No newline at end of file diff --git a/snippets/omit.md b/snippets/omit.md index 239376b5b..01b4f4d8d 100644 --- a/snippets/omit.md +++ b/snippets/omit.md @@ -1,4 +1,7 @@ -### omit +--- +title: omit +tags: object,array,intermediate +--- Omits the key-value pairs corresponding to the given keys from an object. @@ -14,4 +17,4 @@ const omit = (obj, arr) => ```js omit({ a: 1, b: '2', c: 3 }, ['b']); // { 'a': 1, 'c': 3 } -``` +``` \ No newline at end of file diff --git a/snippets/omitBy.md b/snippets/omitBy.md index e30d7b7ad..c45ea2604 100644 --- a/snippets/omitBy.md +++ b/snippets/omitBy.md @@ -1,4 +1,7 @@ -### omitBy +--- +title: omitBy +tags: object,array,function,intermediate +--- Creates an object composed of the properties the given function returns falsy for. The function is invoked with two arguments: (value, key). @@ -14,4 +17,4 @@ const omitBy = (obj, fn) => ```js omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'); // { b: '2' } -``` +``` \ No newline at end of file diff --git a/snippets/on.md b/snippets/on.md index 64a2478c7..a91d58fde 100644 --- a/snippets/on.md +++ b/snippets/on.md @@ -1,4 +1,7 @@ -### on +--- +title: on +tags: browser,event,intermediate +--- Adds an event listener to an element with the ability to use event delegation. @@ -19,4 +22,4 @@ const fn = () => console.log('!'); on(document.body, 'click', fn); // logs '!' upon clicking the body on(document.body, 'click', fn, { target: 'p' }); // logs '!' upon clicking a `p` element child of the body on(document.body, 'click', fn, { options: true }); // use capturing instead of bubbling -``` +``` \ No newline at end of file diff --git a/snippets/onUserInputChange.md b/snippets/onUserInputChange.md index a159c835d..eaa212a68 100644 --- a/snippets/onUserInputChange.md +++ b/snippets/onUserInputChange.md @@ -1,4 +1,7 @@ -### onUserInputChange +--- +title: onUserInputChange +tags: browser,event,advanced +--- Run the callback whenever the user input type changes (`mouse` or `touch`). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops). @@ -27,4 +30,4 @@ const onUserInputChange = callback => { onUserInputChange(type => { console.log('The user is now using', type, 'as an input method.'); }); -``` +``` \ No newline at end of file diff --git a/snippets/once.md b/snippets/once.md index 92ef9c7be..8641e5adc 100644 --- a/snippets/once.md +++ b/snippets/once.md @@ -1,4 +1,7 @@ -### once +--- +title: once +tags: function,intermediate +--- Ensures a function is called only once. @@ -21,4 +24,4 @@ const startApp = function(event) { console.log(this, event); // document.body, MouseEvent }; document.body.addEventListener('click', once(startApp)); // only runs `startApp` once upon click -``` +``` \ No newline at end of file diff --git a/snippets/orderBy.md b/snippets/orderBy.md index ee9318d05..a43b32e0b 100644 --- a/snippets/orderBy.md +++ b/snippets/orderBy.md @@ -1,4 +1,7 @@ -### orderBy +--- +title: orderBy +tags: object,array,intermediate +--- Returns a sorted array of objects ordered by properties and orders. @@ -22,4 +25,4 @@ const orderBy = (arr, props, orders) => const users = [{ 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']); // [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}] -``` +``` \ No newline at end of file diff --git a/snippets/over.md b/snippets/over.md index 8343b9df6..859176db8 100644 --- a/snippets/over.md +++ b/snippets/over.md @@ -1,4 +1,7 @@ -### over +--- +title: over +tags: adapter,function,intermediate +--- Creates a function that invokes each provided function with the arguments it receives and returns the results. @@ -11,4 +14,4 @@ const over = (...fns) => (...args) => fns.map(fn => fn.apply(null, args)); ```js const minMax = over(Math.min, Math.max); minMax(1, 2, 3, 4, 5); // [1,5] -``` +``` \ No newline at end of file diff --git a/snippets/overArgs.md b/snippets/overArgs.md index 7cf3f8fe7..f33dab59d 100644 --- a/snippets/overArgs.md +++ b/snippets/overArgs.md @@ -1,4 +1,7 @@ -### overArgs +--- +title: overArgs +tags: adapter,function,intermediate +--- Creates a function that invokes the provided function with its arguments transformed. @@ -13,4 +16,4 @@ const square = n => n * n; const double = n => n * 2; const fn = overArgs((x, y) => [x, y], [square, double]); fn(9, 3); // [81, 6] -``` +``` \ No newline at end of file diff --git a/snippets/pad.md b/snippets/pad.md index 18e449739..9a750ccde 100644 --- a/snippets/pad.md +++ b/snippets/pad.md @@ -1,4 +1,7 @@ -### pad +--- +title: pad +tags: string,beginner +--- Pads a string on both sides with the specified character, if it's shorter than the specified length. @@ -14,4 +17,4 @@ const pad = (str, length, char = ' ') => pad('cat', 8); // ' cat ' pad(String(42), 6, '0'); // '004200' pad('foobar', 3); // 'foobar' -``` +``` \ No newline at end of file diff --git a/snippets/palindrome.md b/snippets/palindrome.md index eccf8cb0a..497a58eb3 100644 --- a/snippets/palindrome.md +++ b/snippets/palindrome.md @@ -1,4 +1,7 @@ -### palindrome +--- +title: palindrome +tags: string,intermediate +--- Returns `true` if the given string is a palindrome, `false` otherwise. @@ -14,4 +17,4 @@ const palindrome = str => { ```js palindrome('taco cat'); // true -``` +``` \ No newline at end of file diff --git a/snippets/parseCookie.md b/snippets/parseCookie.md index 8363403ae..cbbe24bc5 100644 --- a/snippets/parseCookie.md +++ b/snippets/parseCookie.md @@ -1,4 +1,7 @@ -### parseCookie +--- +title: parseCookie +tags: utility,string,intermediate +--- Parse an HTTP Cookie header string and return an object of all cookie name-value pairs. @@ -19,4 +22,4 @@ const parseCookie = str => ```js parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' } -``` +``` \ No newline at end of file diff --git a/snippets/partial.md b/snippets/partial.md index 533beb8c5..723aeed1b 100644 --- a/snippets/partial.md +++ b/snippets/partial.md @@ -1,4 +1,7 @@ -### partial +--- +title: partial +tags: function,intermediate +--- Creates a function that invokes `fn` with `partials` prepended to the arguments it receives. @@ -12,4 +15,4 @@ const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); const greet = (greeting, name) => greeting + ' ' + name + '!'; const greetHello = partial(greet, 'Hello'); greetHello('John'); // 'Hello John!' -``` +``` \ No newline at end of file diff --git a/snippets/partialRight.md b/snippets/partialRight.md index 56a662c7b..44418aff3 100644 --- a/snippets/partialRight.md +++ b/snippets/partialRight.md @@ -1,4 +1,7 @@ -### partialRight +--- +title: partialRight +tags: function,intermediate +--- Creates a function that invokes `fn` with `partials` appended to the arguments it receives. @@ -12,4 +15,4 @@ const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); const greet = (greeting, name) => greeting + ' ' + name + '!'; const greetJohn = partialRight(greet, 'John'); greetJohn('Hello'); // 'Hello John!' -``` +``` \ No newline at end of file diff --git a/snippets/partition.md b/snippets/partition.md index 8d054c4dc..d08eacb1f 100644 --- a/snippets/partition.md +++ b/snippets/partition.md @@ -1,4 +1,7 @@ -### partition +--- +title: partition +tags: array,object,function,intermediate +--- Groups the elements into two arrays, depending on the provided function's truthiness for each element. @@ -19,4 +22,4 @@ const partition = (arr, fn) => ```js const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }]; partition(users, o => o.active); // [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]] -``` +``` \ No newline at end of file diff --git a/snippets/percentile.md b/snippets/percentile.md index 3522a67d8..413c9e2d7 100644 --- a/snippets/percentile.md +++ b/snippets/percentile.md @@ -1,4 +1,7 @@ -### percentile +--- +title: percentile +tags: math,intermediate +--- Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value. @@ -11,4 +14,4 @@ const percentile = (arr, val) => ```js percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6); // 55 -``` +``` \ No newline at end of file diff --git a/snippets/permutations.md b/snippets/permutations.md index 195bd1a80..331c8af37 100644 --- a/snippets/permutations.md +++ b/snippets/permutations.md @@ -1,4 +1,7 @@ -### permutations +--- +title: permutations +tags: array,recursion,advanced +--- ⚠️ **WARNING**: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries will cause your browser to hang as it tries to solve all the different combinations. @@ -24,4 +27,4 @@ const permutations = arr => { ```js permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ] -``` +``` \ No newline at end of file diff --git a/snippets/pick.md b/snippets/pick.md index 188635dcd..304d244fb 100644 --- a/snippets/pick.md +++ b/snippets/pick.md @@ -1,4 +1,7 @@ -### pick +--- +title: pick +tags: object,array,intermediate +--- Picks the key-value pairs corresponding to the given keys from an object. @@ -11,4 +14,4 @@ const pick = (obj, arr) => ```js pick({ a: 1, b: '2', c: 3 }, ['a', 'c']); // { 'a': 1, 'c': 3 } -``` +``` \ No newline at end of file diff --git a/snippets/pickBy.md b/snippets/pickBy.md index 4083c4ec9..f3c08a8d2 100644 --- a/snippets/pickBy.md +++ b/snippets/pickBy.md @@ -1,4 +1,7 @@ -### pickBy +--- +title: pickBy +tags: object,array,function,intermediate +--- Creates an object composed of the properties the given function returns truthy for. The function is invoked with two arguments: (value, key). @@ -14,4 +17,4 @@ const pickBy = (obj, fn) => ```js pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'); // { 'a': 1, 'c': 3 } -``` +``` \ No newline at end of file diff --git a/snippets/pipeAsyncFunctions.md b/snippets/pipeAsyncFunctions.md index 47d6f620c..7c65d2101 100644 --- a/snippets/pipeAsyncFunctions.md +++ b/snippets/pipeAsyncFunctions.md @@ -1,4 +1,7 @@ -### pipeAsyncFunctions +--- +title: pipeAsyncFunctions +tags: adapter,function,promise,intermediate +--- Performs left-to-right function composition for asynchronous functions. @@ -20,4 +23,4 @@ const sum = pipeAsyncFunctions( (async() => { console.log(await sum(5)); // 15 (after one second) })(); -``` +``` \ No newline at end of file diff --git a/snippets/pipeFunctions.md b/snippets/pipeFunctions.md index 3814f55cb..5de1d9d61 100644 --- a/snippets/pipeFunctions.md +++ b/snippets/pipeFunctions.md @@ -1,4 +1,7 @@ -### pipeFunctions +--- +title: pipeFunctions +tags: adapter,function,intermediate +--- Performs left-to-right function composition. @@ -14,4 +17,4 @@ const add5 = x => x + 5; const multiply = (x, y) => x * y; const multiplyAndAdd5 = pipeFunctions(multiply, add5); multiplyAndAdd5(5, 2); // 15 -``` +``` \ No newline at end of file diff --git a/snippets/pluralize.md b/snippets/pluralize.md index f97588313..b3189971a 100644 --- a/snippets/pluralize.md +++ b/snippets/pluralize.md @@ -1,4 +1,7 @@ -### pluralize +--- +title: pluralize +tags: string,intermediate +--- Returns the singular or plural form of the word based on the input number. If the first argument is an `object`, it will use a closure by returning a function that can auto-pluralize words that don't simply end in `s` if the supplied dictionary contains the word. @@ -25,4 +28,4 @@ const PLURALS = { }; const autoPluralize = pluralize(PLURALS); autoPluralize(2, 'person'); // 'people' -``` +``` \ No newline at end of file diff --git a/snippets/powerset.md b/snippets/powerset.md index 8e427497f..36d409310 100644 --- a/snippets/powerset.md +++ b/snippets/powerset.md @@ -1,4 +1,7 @@ -### powerset +--- +title: powerset +tags: math,beginner +--- Returns the powerset of a given array of numbers. @@ -10,4 +13,4 @@ const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))) ```js powerset([1, 2]); // [[], [1], [2], [2, 1]] -``` +``` \ No newline at end of file diff --git a/snippets/prefix.md b/snippets/prefix.md index 606f13821..0c1b9c216 100644 --- a/snippets/prefix.md +++ b/snippets/prefix.md @@ -1,4 +1,7 @@ -### prefix +--- +title: prefix +tags: browser,utility,intermediate +--- Returns the prefixed version (if necessary) of a CSS property that the browser supports. @@ -18,4 +21,4 @@ const prefix = prop => { ```js prefix('appearance'); // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance' -``` +``` \ No newline at end of file diff --git a/snippets/prettyBytes.md b/snippets/prettyBytes.md index 411d4e0b5..aef44f8ea 100644 --- a/snippets/prettyBytes.md +++ b/snippets/prettyBytes.md @@ -1,4 +1,7 @@ -### prettyBytes +--- +title: prettyBytes +tags: utility,string,math,advanced +--- Converts a number in bytes to a human-readable string. @@ -22,4 +25,4 @@ const prettyBytes = (num, precision = 3, addSpace = true) => { prettyBytes(1000); // "1 KB" prettyBytes(-27145424323.5821, 5); // "-27.145 GB" prettyBytes(123456789, 3, false); // "123MB" -``` +``` \ No newline at end of file diff --git a/snippets/primes.md b/snippets/primes.md index 3a9ae7b51..b3cf25e19 100644 --- a/snippets/primes.md +++ b/snippets/primes.md @@ -1,4 +1,7 @@ -### primes +--- +title: primes +tags: math,array,intermediate +--- Generates primes up to a given number, using the Sieve of Eratosthenes. @@ -16,4 +19,4 @@ const primes = num => { ```js primes(10); // [2,3,5,7] -``` +``` \ No newline at end of file diff --git a/snippets/promisify.md b/snippets/promisify.md index 19d99328c..b65136d83 100644 --- a/snippets/promisify.md +++ b/snippets/promisify.md @@ -1,4 +1,7 @@ -### promisify +--- +title: promisify +tags: adapter,function,promise,intermediate +--- Converts an asynchronous function to return a promise. @@ -17,4 +20,4 @@ const promisify = func => (...args) => ```js const delay = promisify((d, cb) => setTimeout(cb, d)); delay(2000).then(() => console.log('Hi!')); // // Promise resolves after 2s -``` +``` \ No newline at end of file diff --git a/snippets/pull.md b/snippets/pull.md index 609032fb1..9da74adfe 100644 --- a/snippets/pull.md +++ b/snippets/pull.md @@ -1,4 +1,7 @@ -### pull +--- +title: pull +tags: array,intermediate +--- Mutates the original array to filter out the values specified. @@ -19,4 +22,4 @@ const pull = (arr, ...args) => { ```js let myArray = ['a', 'b', 'c', 'a', 'b', 'c']; pull(myArray, 'a', 'c'); // myArray = [ 'b', 'b' ] -``` +``` \ No newline at end of file diff --git a/snippets/pullAtIndex.md b/snippets/pullAtIndex.md index 024deabbf..b08066405 100644 --- a/snippets/pullAtIndex.md +++ b/snippets/pullAtIndex.md @@ -1,4 +1,7 @@ -### pullAtIndex +--- +title: pullAtIndex +tags: array,advanced +--- Mutates the original array to filter out the values at the specified indexes. @@ -21,4 +24,4 @@ const pullAtIndex = (arr, pullArr) => { ```js let myArray = ['a', 'b', 'c', 'd']; let pulled = pullAtIndex(myArray, [1, 3]); // myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ] -``` +``` \ No newline at end of file diff --git a/snippets/pullAtValue.md b/snippets/pullAtValue.md index 93fa5e988..0db8c8f43 100644 --- a/snippets/pullAtValue.md +++ b/snippets/pullAtValue.md @@ -1,4 +1,7 @@ -### pullAtValue +--- +title: pullAtValue +tags: array,advanced +--- Mutates the original array to filter out the values specified. Returns the removed elements. @@ -20,4 +23,4 @@ const pullAtValue = (arr, pullArr) => { ```js let myArray = ['a', 'b', 'c', 'd']; let pulled = pullAtValue(myArray, ['b', 'd']); // myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ] -``` +``` \ No newline at end of file diff --git a/snippets/pullBy.md b/snippets/pullBy.md index 6be1976dc..0d2cb34a2 100644 --- a/snippets/pullBy.md +++ b/snippets/pullBy.md @@ -1,4 +1,7 @@ -### pullBy +--- +title: pullBy +tags: array,function,advanced +--- Mutates the original array to filter out the values specified, based on a given iterator function. @@ -22,4 +25,4 @@ const pullBy = (arr, ...args) => { ```js var myArray = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }]; pullBy(myArray, [{ x: 1 }, { x: 3 }], o => o.x); // myArray = [{ x: 2 }] -``` +``` \ No newline at end of file diff --git a/snippets/radsToDegrees.md b/snippets/radsToDegrees.md index 3cd4fa8d4..85c16d053 100644 --- a/snippets/radsToDegrees.md +++ b/snippets/radsToDegrees.md @@ -1,4 +1,7 @@ -### radsToDegrees +--- +title: radsToDegrees +tags: math,beginner +--- Converts an angle from radians to degrees. @@ -10,4 +13,4 @@ const radsToDegrees = rad => (rad * 180.0) / Math.PI; ```js radsToDegrees(Math.PI / 2); // 90 -``` +``` \ No newline at end of file diff --git a/snippets/randomHexColorCode.md b/snippets/randomHexColorCode.md index af8b723f2..4fe7818ba 100644 --- a/snippets/randomHexColorCode.md +++ b/snippets/randomHexColorCode.md @@ -1,4 +1,7 @@ -### randomHexColorCode +--- +title: randomHexColorCode +tags: utility,random,beginner +--- Generates a random hexadecimal color code. @@ -13,4 +16,4 @@ const randomHexColorCode = () => { ```js randomHexColorCode(); // "#e34155" -``` +``` \ No newline at end of file diff --git a/snippets/randomIntArrayInRange.md b/snippets/randomIntArrayInRange.md index a8e38cf2f..075bece9d 100644 --- a/snippets/randomIntArrayInRange.md +++ b/snippets/randomIntArrayInRange.md @@ -1,4 +1,7 @@ -### randomIntArrayInRange +--- +title: randomIntArrayInRange +tags: math,utility,random,intermediate +--- Returns an array of n random integers in the specified range. @@ -11,4 +14,4 @@ const randomIntArrayInRange = (min, max, n = 1) => ```js randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ] -``` +``` \ No newline at end of file diff --git a/snippets/randomIntegerInRange.md b/snippets/randomIntegerInRange.md index e9dbe1df2..177c61983 100644 --- a/snippets/randomIntegerInRange.md +++ b/snippets/randomIntegerInRange.md @@ -1,4 +1,7 @@ -### randomIntegerInRange +--- +title: randomIntegerInRange +tags: math,utility,random,beginner +--- Returns a random integer in the specified range. @@ -10,4 +13,4 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min ```js randomIntegerInRange(0, 5); // 2 -``` +``` \ No newline at end of file diff --git a/snippets/randomNumberInRange.md b/snippets/randomNumberInRange.md index da5cd6640..ff6a5a1dd 100644 --- a/snippets/randomNumberInRange.md +++ b/snippets/randomNumberInRange.md @@ -1,4 +1,7 @@ -### randomNumberInRange +--- +title: randomNumberInRange +tags: math,utility,random,beginner +--- Returns a random number in the specified range. @@ -10,4 +13,4 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; ```js randomNumberInRange(2, 10); // 6.0211363285087005 -``` +``` \ No newline at end of file diff --git a/snippets/readFileLines.md b/snippets/readFileLines.md index e68c4633a..f39dd0a66 100644 --- a/snippets/readFileLines.md +++ b/snippets/readFileLines.md @@ -1,4 +1,7 @@ -### readFileLines +--- +title: readFileLines +tags: node,array,string,beginner +--- Returns an array of lines from the specified file. @@ -25,5 +28,4 @@ contents of test.txt : */ let arr = readFileLines('test.txt'); console.log(arr); // ['line1', 'line2', 'line3'] -``` - +``` \ No newline at end of file diff --git a/snippets/rearg.md b/snippets/rearg.md index 48096626c..61443d363 100644 --- a/snippets/rearg.md +++ b/snippets/rearg.md @@ -1,4 +1,7 @@ -### rearg +--- +title: rearg +tags: adapter,function,intermediate +--- Creates a function that invokes the provided function with its arguments arranged according to the specified indexes. @@ -16,4 +19,4 @@ var rearged = rearg( [2, 0, 1] ); rearged('b', 'c', 'a'); // ['a', 'b', 'c'] -``` +``` \ No newline at end of file diff --git a/snippets/recordAnimationFrames.md b/snippets/recordAnimationFrames.md index a775e0460..37975c298 100644 --- a/snippets/recordAnimationFrames.md +++ b/snippets/recordAnimationFrames.md @@ -1,4 +1,7 @@ -### recordAnimationFrames +--- +title: recordAnimationFrames +tags: browser,utility,intermediate +--- Invokes the provided callback on each animation frame. @@ -36,4 +39,4 @@ const recorder = recordAnimationFrames(cb); // logs 'Animation frame fired' on e recorder.stop(); // stops logging recorder.start(); // starts again const recorder2 = recordAnimationFrames(cb, false); // `start` needs to be explicitly called to begin recording frames -``` +``` \ No newline at end of file diff --git a/snippets/redirect.md b/snippets/redirect.md index 112b30bff..8d454f07f 100644 --- a/snippets/redirect.md +++ b/snippets/redirect.md @@ -1,4 +1,7 @@ -### redirect +--- +title: redirect +tags: browser,url,beginner +--- Redirects to a specified URL. @@ -12,4 +15,4 @@ const redirect = (url, asLink = true) => ```js redirect('https://google.com'); -``` +``` \ No newline at end of file diff --git a/snippets/reduceSuccessive.md b/snippets/reduceSuccessive.md index e5338946f..0e6af750c 100644 --- a/snippets/reduceSuccessive.md +++ b/snippets/reduceSuccessive.md @@ -1,4 +1,7 @@ -### reduceSuccessive +--- +title: reduceSuccessive +tags: array,function,intermediate +--- Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values. @@ -11,4 +14,4 @@ const reduceSuccessive = (arr, fn, acc) => ```js reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0); // [0, 1, 3, 6, 10, 15, 21] -``` +``` \ No newline at end of file diff --git a/snippets/reduceWhich.md b/snippets/reduceWhich.md index 54df46e05..582962eca 100644 --- a/snippets/reduceWhich.md +++ b/snippets/reduceWhich.md @@ -1,4 +1,7 @@ -### reduceWhich +--- +title: reduceWhich +tags: array,function,intermediate +--- Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule. @@ -17,4 +20,4 @@ reduceWhich( [{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }], (a, b) => a.age - b.age ); // {name: "Lucy", age: 9} -``` +``` \ No newline at end of file diff --git a/snippets/reducedFilter.md b/snippets/reducedFilter.md index 0c831c8af..24ac75064 100644 --- a/snippets/reducedFilter.md +++ b/snippets/reducedFilter.md @@ -1,4 +1,7 @@ -### reducedFilter +--- +title: reducedFilter +tags: array,intermediate +--- Filter an array of objects based on a condition while also filtering out unspecified keys. @@ -30,4 +33,4 @@ const data = [ ]; reducedFilter(data, ['id', 'name'], item => item.age > 24); // [{ id: 2, name: 'mike'}] -``` +``` \ No newline at end of file diff --git a/snippets/reject.md b/snippets/reject.md index 2dd6fb07d..cc265f2b1 100644 --- a/snippets/reject.md +++ b/snippets/reject.md @@ -1,4 +1,7 @@ -### reject +--- +title: reject +tags: array,beginner +--- Takes a predicate and array, like `Array.prototype.filter()`, but only keeps `x` if `pred(x) === false`. @@ -9,4 +12,4 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args)); ```js reject(x => x % 2 === 0, [1, 2, 3, 4, 5]); // [1, 3, 5] reject(word => word.length > 4, ['Apple', 'Pear', 'Kiwi', 'Banana']); // ['Pear', 'Kiwi'] -``` +``` \ No newline at end of file diff --git a/snippets/remove.md b/snippets/remove.md index 58de9c2e0..1bc9b3abb 100644 --- a/snippets/remove.md +++ b/snippets/remove.md @@ -1,4 +1,7 @@ -### remove +--- +title: remove +tags: array,intermediate +--- Removes elements from an array for which the given function returns `false`. @@ -17,4 +20,4 @@ const remove = (arr, func) => ```js remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4] -``` +``` \ No newline at end of file diff --git a/snippets/removeNonASCII.md b/snippets/removeNonASCII.md index 997f08740..532ab45cc 100644 --- a/snippets/removeNonASCII.md +++ b/snippets/removeNonASCII.md @@ -1,4 +1,7 @@ -### removeNonASCII +--- +title: removeNonASCII +tags: string,regexp,intermediate +--- Removes non-printable ASCII characters. @@ -10,4 +13,4 @@ const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, ''); ```js removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ'); // 'lorem-ipsum' -``` +``` \ No newline at end of file diff --git a/snippets/renameKeys.md b/snippets/renameKeys.md index 2a852c2fa..ca25300c6 100644 --- a/snippets/renameKeys.md +++ b/snippets/renameKeys.md @@ -1,4 +1,7 @@ -### renameKeys +--- +title: renameKeys +tags: object,intermediate +--- Replaces the names of multiple object keys with the values provided. @@ -18,4 +21,4 @@ const renameKeys = (keysMap, obj) => ```js const obj = { name: 'Bobo', job: 'Front-End Master', shoeSize: 100 }; renameKeys({ name: 'firstName', job: 'passion' }, obj); // { firstName: 'Bobo', passion: 'Front-End Master', shoeSize: 100 } -``` +``` \ No newline at end of file diff --git a/snippets/reverseString.md b/snippets/reverseString.md index 8b216478d..a55286176 100644 --- a/snippets/reverseString.md +++ b/snippets/reverseString.md @@ -1,4 +1,7 @@ -### reverseString +--- +title: reverseString +tags: string,array,beginner +--- Reverses a string. @@ -11,4 +14,4 @@ const reverseString = str => [...str].reverse().join(''); ```js reverseString('foobar'); // 'raboof' -``` +``` \ No newline at end of file diff --git a/snippets/round.md b/snippets/round.md index 37340ecf7..7ecacb04b 100644 --- a/snippets/round.md +++ b/snippets/round.md @@ -1,4 +1,7 @@ -### round +--- +title: round +tags: math,intermediate +--- Rounds a number to a specified amount of digits. @@ -11,4 +14,4 @@ const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${ ```js round(1.005, 2); // 1.01 -``` +``` \ No newline at end of file diff --git a/snippets/runAsync.md b/snippets/runAsync.md index f260aa37e..e96aa5f5e 100644 --- a/snippets/runAsync.md +++ b/snippets/runAsync.md @@ -1,4 +1,7 @@ -### runAsync +--- +title: runAsync +tags: browser,function,advanced,promise,url +--- 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. @@ -41,4 +44,4 @@ runAsync(longRunningFunction).then(console.log); // 209685000000 runAsync(() => 10 ** 3).then(console.log); // 1000 let outsideVariable = 50; runAsync(() => typeof outsideVariable).then(console.log); // 'undefined' -``` +``` \ No newline at end of file diff --git a/snippets/runPromisesInSeries.md b/snippets/runPromisesInSeries.md index 457f6915c..468d5dfd1 100644 --- a/snippets/runPromisesInSeries.md +++ b/snippets/runPromisesInSeries.md @@ -1,4 +1,7 @@ -### runPromisesInSeries +--- +title: runPromisesInSeries +tags: function,promise,intermediate +--- Runs an array of promises in series. @@ -11,4 +14,4 @@ const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.r ```js 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 -``` +``` \ No newline at end of file diff --git a/snippets/sample.md b/snippets/sample.md index e900209b3..31ac69bcb 100644 --- a/snippets/sample.md +++ b/snippets/sample.md @@ -1,4 +1,7 @@ -### sample +--- +title: sample +tags: array,random,beginner +--- Returns a random element from an array. @@ -11,4 +14,4 @@ const sample = arr => arr[Math.floor(Math.random() * arr.length)]; ```js sample([3, 7, 9, 11]); // 9 -``` +``` \ No newline at end of file diff --git a/snippets/sampleSize.md b/snippets/sampleSize.md index d9f2717d5..10ee3a345 100644 --- a/snippets/sampleSize.md +++ b/snippets/sampleSize.md @@ -1,4 +1,7 @@ -### sampleSize +--- +title: sampleSize +tags: array,random,intermediate +--- Gets `n` random elements at unique keys from `array` up to the size of `array`. @@ -20,4 +23,4 @@ const sampleSize = ([...arr], n = 1) => { ```js sampleSize([1, 2, 3], 2); // [3,1] sampleSize([1, 2, 3], 4); // [2,3,1] -``` +``` \ No newline at end of file diff --git a/snippets/scrollToTop.md b/snippets/scrollToTop.md index 8a78a8030..d1f866b65 100644 --- a/snippets/scrollToTop.md +++ b/snippets/scrollToTop.md @@ -1,4 +1,7 @@ -### scrollToTop +--- +title: scrollToTop +tags: browser,intermediate +--- Smooth-scrolls to the top of the page. @@ -17,4 +20,4 @@ const scrollToTop = () => { ```js scrollToTop(); -``` +``` \ No newline at end of file diff --git a/snippets/sdbm.md b/snippets/sdbm.md index 48a88bfdf..fdd4d3090 100644 --- a/snippets/sdbm.md +++ b/snippets/sdbm.md @@ -1,4 +1,7 @@ -### sdbm +--- +title: sdbm +tags: math,utility,intermediate +--- Hashes the input string into a whole number. @@ -17,4 +20,4 @@ const sdbm = str => { ```js sdbm('name'); // -3521204949 -``` +``` \ No newline at end of file diff --git a/snippets/serializeCookie.md b/snippets/serializeCookie.md index 4b434351f..b5dade2e7 100644 --- a/snippets/serializeCookie.md +++ b/snippets/serializeCookie.md @@ -1,4 +1,7 @@ -### serializeCookie +--- +title: serializeCookie +tags: utility,string,intermediate +--- Serialize a cookie name-value pair into a Set-Cookie header string. @@ -10,4 +13,4 @@ const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIC ```js serializeCookie('foo', 'bar'); // 'foo=bar' -``` +``` \ No newline at end of file diff --git a/snippets/serializeForm.md b/snippets/serializeForm.md index 393c63d4b..725dfcffc 100644 --- a/snippets/serializeForm.md +++ b/snippets/serializeForm.md @@ -1,4 +1,7 @@ -### serializeForm +--- +title: serializeForm +tags: browser,string,intermediate +--- Encode a set of form elements as a query string. @@ -13,4 +16,4 @@ const serializeForm = form => ```js serializeForm(document.querySelector('#form')); // email=test%40email.com&name=Test%20Name -``` +``` \ No newline at end of file diff --git a/snippets/setStyle.md b/snippets/setStyle.md index b85c5207c..4f7aa64ab 100644 --- a/snippets/setStyle.md +++ b/snippets/setStyle.md @@ -1,4 +1,7 @@ -### setStyle +--- +title: setStyle +tags: browser,beginner +--- Sets the value of a CSS rule for the specified element. @@ -10,4 +13,4 @@ const setStyle = (el, ruleName, val) => (el.style[ruleName] = val); ```js setStyle(document.querySelector('p'), 'font-size', '20px'); // The first

    element on the page will have a font-size of 20px -``` +``` \ No newline at end of file diff --git a/snippets/shallowClone.md b/snippets/shallowClone.md index 10eb3a418..b56010540 100644 --- a/snippets/shallowClone.md +++ b/snippets/shallowClone.md @@ -1,4 +1,7 @@ -### shallowClone +--- +title: shallowClone +tags: object,beginner +--- Creates a shallow clone of an object. @@ -11,4 +14,4 @@ const shallowClone = obj => Object.assign({}, obj); ```js const a = { x: true, y: 1 }; const b = shallowClone(a); // a !== b -``` +``` \ No newline at end of file diff --git a/snippets/shank.md b/snippets/shank.md index 1f5b2e25f..171345476 100644 --- a/snippets/shank.md +++ b/snippets/shank.md @@ -1,4 +1,7 @@ -### shank +--- +title: shank +tags: array,intermediate +--- Has the same functionality as [`Array.prototype.splice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice), but returning a new array instead of mutating the original array. @@ -20,4 +23,4 @@ const names = ['alpha', 'bravo', 'charlie']; const namesAndDelta = shank(names, 1, 0, 'delta'); // [ 'alpha', 'delta', 'bravo', 'charlie' ] const namesNoBravo = shank(names, 1, 1); // [ 'alpha', 'charlie' ] console.log(names); // ['alpha', 'bravo', 'charlie'] -``` +``` \ No newline at end of file diff --git a/snippets/show.md b/snippets/show.md index f58abf52e..62a6cf4e7 100644 --- a/snippets/show.md +++ b/snippets/show.md @@ -1,4 +1,7 @@ -### show +--- +title: show +tags: browser,css,beginner +--- Shows all the elements specified. @@ -10,4 +13,4 @@ const show = (...el) => [...el].forEach(e => (e.style.display = '')); ```js show(...document.querySelectorAll('img')); // Shows all elements on the page -``` +``` \ No newline at end of file diff --git a/snippets/shuffle.md b/snippets/shuffle.md index ceffd8a8f..3cce2ea04 100644 --- a/snippets/shuffle.md +++ b/snippets/shuffle.md @@ -1,4 +1,7 @@ -### shuffle +--- +title: shuffle +tags: array,random,intermediate +--- Randomizes the order of the values of an array, returning a new array. @@ -18,4 +21,4 @@ const shuffle = ([...arr]) => { ```js const foo = [1, 2, 3]; shuffle(foo); // [2, 3, 1], foo = [1, 2, 3] -``` +``` \ No newline at end of file diff --git a/snippets/similarity.md b/snippets/similarity.md index 0d2175cb6..3a2539574 100644 --- a/snippets/similarity.md +++ b/snippets/similarity.md @@ -1,4 +1,7 @@ -### similarity +--- +title: similarity +tags: array,math,beginner +--- Returns an array of elements that appear in both arrays. @@ -10,4 +13,4 @@ const similarity = (arr, values) => arr.filter(v => values.includes(v)); ```js similarity([1, 2, 3], [1, 2, 4]); // [1, 2] -``` +``` \ No newline at end of file diff --git a/snippets/size.md b/snippets/size.md index 03b2c04b8..e03f338fc 100644 --- a/snippets/size.md +++ b/snippets/size.md @@ -1,4 +1,7 @@ -### size +--- +title: size +tags: object,array,string,intermediate +--- Get size of arrays, objects or strings. @@ -24,4 +27,4 @@ const size = val => size([1, 2, 3, 4, 5]); // 5 size('size'); // 4 size({ one: 1, two: 2, three: 3 }); // 3 -``` +``` \ No newline at end of file diff --git a/snippets/sleep.md b/snippets/sleep.md index ca1d467ef..61ec126c2 100644 --- a/snippets/sleep.md +++ b/snippets/sleep.md @@ -1,4 +1,7 @@ -### sleep +--- +title: sleep +tags: function,promise,intermediate +--- Delays the execution of an asynchronous function. @@ -14,4 +17,4 @@ async function sleepyWork() { await sleep(1000); console.log('I woke up after 1 second.'); } -``` +``` \ No newline at end of file diff --git a/snippets/smoothScroll.md b/snippets/smoothScroll.md index c3e045ab7..a8046462a 100644 --- a/snippets/smoothScroll.md +++ b/snippets/smoothScroll.md @@ -1,4 +1,7 @@ -### smoothScroll +--- +title: smoothScroll +tags: browser,css,intermediate +--- Smoothly scrolls the element on which it's called into the visible area of the browser window. @@ -15,4 +18,4 @@ const smoothScroll = element => ```js smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar smoothScroll('.fooBar'); // scrolls smoothly to the first element with a class of fooBar -``` +``` \ No newline at end of file diff --git a/snippets/sortCharactersInString.md b/snippets/sortCharactersInString.md index 71677e5d2..b7a649f4d 100644 --- a/snippets/sortCharactersInString.md +++ b/snippets/sortCharactersInString.md @@ -1,4 +1,7 @@ -### sortCharactersInString +--- +title: sortCharactersInString +tags: string,beginner +--- Alphabetically sorts the characters in a string. @@ -10,4 +13,4 @@ const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b) ```js sortCharactersInString('cabbage'); // 'aabbceg' -``` +``` \ No newline at end of file diff --git a/snippets/sortedIndex.md b/snippets/sortedIndex.md index ab6745265..1b36afd4b 100644 --- a/snippets/sortedIndex.md +++ b/snippets/sortedIndex.md @@ -1,4 +1,7 @@ -### sortedIndex +--- +title: sortedIndex +tags: array,math,intermediate +--- Returns the lowest index at which value should be inserted into array in order to maintain its sort order. @@ -16,4 +19,4 @@ const sortedIndex = (arr, n) => { ```js sortedIndex([5, 3, 2, 1], 4); // 1 sortedIndex([30, 50], 40); // 1 -``` +``` \ No newline at end of file diff --git a/snippets/sortedIndexBy.md b/snippets/sortedIndexBy.md index 2be5c1601..780b62ba1 100644 --- a/snippets/sortedIndexBy.md +++ b/snippets/sortedIndexBy.md @@ -1,4 +1,7 @@ -### sortedIndexBy +--- +title: sortedIndexBy +tags: array,math,function,intermediate +--- Returns the lowest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function. @@ -16,4 +19,4 @@ const sortedIndexBy = (arr, n, fn) => { ```js sortedIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x); // 0 -``` +``` \ No newline at end of file diff --git a/snippets/sortedLastIndex.md b/snippets/sortedLastIndex.md index f4ef70e29..a0c3a9e4e 100644 --- a/snippets/sortedLastIndex.md +++ b/snippets/sortedLastIndex.md @@ -1,4 +1,7 @@ -### sortedLastIndex +--- +title: sortedLastIndex +tags: array,math,intermediate +--- Returns the highest index at which value should be inserted into array in order to maintain its sort order. @@ -15,4 +18,4 @@ const sortedLastIndex = (arr, n) => { ```js sortedLastIndex([10, 20, 30, 30, 40], 30); // 4 -``` +``` \ No newline at end of file diff --git a/snippets/sortedLastIndexBy.md b/snippets/sortedLastIndexBy.md index cd87e60ef..2abc1f40b 100644 --- a/snippets/sortedLastIndexBy.md +++ b/snippets/sortedLastIndexBy.md @@ -1,4 +1,7 @@ -### sortedLastIndexBy +--- +title: sortedLastIndexBy +tags: array,math,function,intermediate +--- Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function. @@ -20,4 +23,4 @@ const sortedLastIndexBy = (arr, n, fn) => { ```js sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x); // 1 -``` +``` \ No newline at end of file diff --git a/snippets/splitLines.md b/snippets/splitLines.md index 6062775c4..b1fe3827c 100644 --- a/snippets/splitLines.md +++ b/snippets/splitLines.md @@ -1,4 +1,7 @@ -### splitLines +--- +title: splitLines +tags: string,beginner +--- Splits a multiline string into an array of lines. @@ -10,4 +13,4 @@ const splitLines = str => str.split(/\r?\n/); ```js splitLines('This\nis a\nmultiline\nstring.\n'); // ['This', 'is a', 'multiline', 'string.' , ''] -``` +``` \ No newline at end of file diff --git a/snippets/spreadOver.md b/snippets/spreadOver.md index 7b05e8088..47955e7ab 100644 --- a/snippets/spreadOver.md +++ b/snippets/spreadOver.md @@ -1,14 +1,17 @@ -### spreadOver - +--- +title: spreadOver +tags: adapter,intermediate +--- + Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. -Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. - +Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. + ```js const spreadOver = fn => argsArr => fn(...argsArr); -``` - +``` + ```js const arrayMax = spreadOver(Math.max); arrayMax([1, 2, 3]); // 3 -``` +``` \ No newline at end of file diff --git a/snippets/stableSort.md b/snippets/stableSort.md index be8501701..584e19847 100644 --- a/snippets/stableSort.md +++ b/snippets/stableSort.md @@ -1,4 +1,7 @@ -### stableSort +--- +title: stableSort +tags: array,sort,advanced,intermediate +--- Performs stable sorting of an array, preserving the initial indexes of items when their values are the same. Does not mutate the original array, but returns a new array instead. @@ -18,4 +21,4 @@ const stableSort = (arr, compare) => ```js const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const stable = stableSort(arr, () => 0); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -``` +``` \ No newline at end of file diff --git a/snippets/standardDeviation.md b/snippets/standardDeviation.md index 911342662..3694627a6 100644 --- a/snippets/standardDeviation.md +++ b/snippets/standardDeviation.md @@ -1,4 +1,7 @@ -### standardDeviation +--- +title: standardDeviation +tags: math,array,intermediate +--- Returns the standard deviation of an array of numbers. @@ -19,4 +22,4 @@ const standardDeviation = (arr, usePopulation = false) => { ```js standardDeviation([10, 2, 38, 23, 38, 23, 21]); // 13.284434142114991 (sample) standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (population) -``` +``` \ No newline at end of file diff --git a/snippets/stringPermutations.md b/snippets/stringPermutations.md index d16e463a3..6345b517a 100644 --- a/snippets/stringPermutations.md +++ b/snippets/stringPermutations.md @@ -1,4 +1,7 @@ -### stringPermutations +--- +title: stringPermutations +tags: string,recursion,advanced +--- ⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations. @@ -24,4 +27,4 @@ const stringPermutations = str => { ```js stringPermutations('abc'); // ['abc','acb','bac','bca','cab','cba'] -``` +``` \ No newline at end of file diff --git a/snippets/stripHTMLTags.md b/snippets/stripHTMLTags.md index 8c507d27b..819159734 100644 --- a/snippets/stripHTMLTags.md +++ b/snippets/stripHTMLTags.md @@ -1,4 +1,7 @@ -### stripHTMLTags +--- +title: stripHTMLTags +tags: string,utility,regexp,beginner +--- Removes HTML/XML tags from string. @@ -10,4 +13,4 @@ const stripHTMLTags = str => str.replace(/<[^>]*>/g, ''); ```js stripHTMLTags('

    lorem ipsum

    '); // 'lorem ipsum' -``` +``` \ No newline at end of file diff --git a/snippets/sum.md b/snippets/sum.md index 2bc3a59ac..a6a25c807 100644 --- a/snippets/sum.md +++ b/snippets/sum.md @@ -1,4 +1,7 @@ -### sum +--- +title: sum +tags: math,array,beginner +--- Returns the sum of two or more numbers/arrays. @@ -11,4 +14,4 @@ const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0); ```js sum(1, 2, 3, 4); // 10 sum(...[1, 2, 3, 4]); // 10 -``` +``` \ No newline at end of file diff --git a/snippets/sumBy.md b/snippets/sumBy.md index 82ba9c7e8..2b8ac7030 100644 --- a/snippets/sumBy.md +++ b/snippets/sumBy.md @@ -1,4 +1,7 @@ -### sumBy +--- +title: sumBy +tags: math,array,function,intermediate +--- Returns the sum of an array, after mapping each element to a value using the provided function. @@ -12,4 +15,4 @@ const sumBy = (arr, fn) => ```js sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 20 sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 20 -``` +``` \ No newline at end of file diff --git a/snippets/sumPower.md b/snippets/sumPower.md index a89c640d5..e54bbb14a 100644 --- a/snippets/sumPower.md +++ b/snippets/sumPower.md @@ -1,4 +1,7 @@ -### sumPower +--- +title: sumPower +tags: math,intermediate +--- Returns the sum of the powers of all the numbers from `start` to `end` (both inclusive). @@ -18,4 +21,4 @@ const sumPower = (end, power = 2, start = 1) => sumPower(10); // 385 sumPower(10, 3); // 3025 sumPower(10, 3, 5); // 2925 -``` +``` \ No newline at end of file diff --git a/snippets/symmetricDifference.md b/snippets/symmetricDifference.md index 52391cba6..0dfeb638d 100644 --- a/snippets/symmetricDifference.md +++ b/snippets/symmetricDifference.md @@ -1,4 +1,7 @@ -### symmetricDifference +--- +title: symmetricDifference +tags: array,math,intermediate +--- Returns the symmetric difference between two arrays, without filtering out duplicate values. @@ -15,4 +18,4 @@ const symmetricDifference = (a, b) => { ```js symmetricDifference([1, 2, 3], [1, 2, 4]); // [3, 4] symmetricDifference([1, 2, 2], [1, 3, 1]); // [2, 2, 3] -``` +``` \ No newline at end of file diff --git a/snippets/symmetricDifferenceBy.md b/snippets/symmetricDifferenceBy.md index f7cce4a6a..dff8d982d 100644 --- a/snippets/symmetricDifferenceBy.md +++ b/snippets/symmetricDifferenceBy.md @@ -1,4 +1,7 @@ -### symmetricDifferenceBy +--- +title: symmetricDifferenceBy +tags: array,function,intermediate +--- Returns the symmetric difference between two arrays, after applying the provided function to each array element of both. @@ -14,4 +17,4 @@ const symmetricDifferenceBy = (a, b, fn) => { ```js symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [ 1.2, 3.4 ] -``` +``` \ No newline at end of file diff --git a/snippets/symmetricDifferenceWith.md b/snippets/symmetricDifferenceWith.md index 50cb8eda5..51528b595 100644 --- a/snippets/symmetricDifferenceWith.md +++ b/snippets/symmetricDifferenceWith.md @@ -1,4 +1,7 @@ -### symmetricDifferenceWith +--- +title: symmetricDifferenceWith +tags: array,function,intermediate +--- Returns the symmetric difference between two arrays, using a provided function as a comparator. @@ -17,4 +20,4 @@ symmetricDifferenceWith( [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b) ); // [1, 1.2, 3.9] -``` +``` \ No newline at end of file diff --git a/snippets/tail.md b/snippets/tail.md index ec095679e..88e292ed4 100644 --- a/snippets/tail.md +++ b/snippets/tail.md @@ -1,4 +1,7 @@ -### tail +--- +title: tail +tags: array,beginner +--- Returns all elements in an array except for the first one. @@ -11,4 +14,4 @@ const tail = arr => (arr.length > 1 ? arr.slice(1) : arr); ```js tail([1, 2, 3]); // [2,3] tail([1]); // [1] -``` +``` \ No newline at end of file diff --git a/snippets/take.md b/snippets/take.md index df25bb368..12fafe510 100644 --- a/snippets/take.md +++ b/snippets/take.md @@ -1,4 +1,7 @@ -### take +--- +title: take +tags: array,beginner +--- Returns an array with n elements removed from the beginning. @@ -11,4 +14,4 @@ const take = (arr, n = 1) => arr.slice(0, n); ```js take([1, 2, 3], 5); // [1, 2, 3] take([1, 2, 3], 0); // [] -``` +``` \ No newline at end of file diff --git a/snippets/takeRight.md b/snippets/takeRight.md index b552f494c..3e6c8be07 100644 --- a/snippets/takeRight.md +++ b/snippets/takeRight.md @@ -1,4 +1,7 @@ -### takeRight +--- +title: takeRight +tags: array,intermediate +--- Returns an array with n elements removed from the end. @@ -11,4 +14,4 @@ const takeRight = (arr, n = 1) => arr.slice(arr.length - n, arr.length); ```js takeRight([1, 2, 3], 2); // [ 2, 3 ] takeRight([1, 2, 3]); // [3] -``` +``` \ No newline at end of file diff --git a/snippets/takeRightWhile.md b/snippets/takeRightWhile.md index 28a5c789a..883527262 100644 --- a/snippets/takeRightWhile.md +++ b/snippets/takeRightWhile.md @@ -1,4 +1,7 @@ -### takeRightWhile +--- +title: takeRightWhile +tags: array,function,intermediate +--- Removes elements from the end of an array until the passed function returns `true`. Returns the removed elements. @@ -11,4 +14,4 @@ const takeRightWhile = (arr, func) => ```js takeRightWhile([1, 2, 3, 4], n => n < 3); // [3, 4] -``` +``` \ No newline at end of file diff --git a/snippets/takeWhile.md b/snippets/takeWhile.md index eb123de82..6a7f79bb8 100644 --- a/snippets/takeWhile.md +++ b/snippets/takeWhile.md @@ -1,4 +1,7 @@ -### takeWhile +--- +title: takeWhile +tags: array,function,intermediate +--- Removes elements in an array until the passed function returns `true`. Returns the removed elements. @@ -14,4 +17,4 @@ const takeWhile = (arr, func) => { ```js takeWhile([1, 2, 3, 4], n => n >= 3); // [1, 2] -``` +``` \ No newline at end of file diff --git a/snippets/throttle.md b/snippets/throttle.md index 3b9801d36..b49a07950 100644 --- a/snippets/throttle.md +++ b/snippets/throttle.md @@ -1,4 +1,7 @@ -### throttle +--- +title: throttle +tags: function,advanced +--- Creates a throttled function that only invokes the provided function at most once per every `wait` milliseconds @@ -38,4 +41,4 @@ window.addEventListener( console.log(window.innerHeight); }, 250) ); // Will log the window dimensions at most every 250ms -``` +``` \ No newline at end of file diff --git a/snippets/timeTaken.md b/snippets/timeTaken.md index d6193e4d9..71011d46e 100644 --- a/snippets/timeTaken.md +++ b/snippets/timeTaken.md @@ -1,4 +1,7 @@ -### timeTaken +--- +title: timeTaken +tags: utility,beginner +--- Measures the time taken by a function to execute. @@ -15,4 +18,4 @@ const timeTaken = callback => { ```js timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms -``` +``` \ No newline at end of file diff --git a/snippets/times.md b/snippets/times.md index 2563ff5bc..7197dd893 100644 --- a/snippets/times.md +++ b/snippets/times.md @@ -1,4 +1,7 @@ -### times +--- +title: times +tags: function,intermediate +--- Iterates over a callback `n` times @@ -16,4 +19,4 @@ const times = (n, fn, context = undefined) => { var output = ''; times(5, i => (output += i)); console.log(output); // 01234 -``` +``` \ No newline at end of file diff --git a/snippets/toCamelCase.md b/snippets/toCamelCase.md index 393082f77..ee27e7997 100644 --- a/snippets/toCamelCase.md +++ b/snippets/toCamelCase.md @@ -1,4 +1,7 @@ -### toCamelCase +--- +title: toCamelCase +tags: string,regexp,intermediate +--- Converts a string to camelcase. @@ -21,4 +24,4 @@ toCamelCase('some_database_field_name'); // 'someDatabaseFieldName' toCamelCase('Some label that needs to be camelized'); // 'someLabelThatNeedsToBeCamelized' toCamelCase('some-javascript-property'); // 'someJavascriptProperty' toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'); // 'someMixedStringWithSpacesUnderscoresAndHyphens' -``` +``` \ No newline at end of file diff --git a/snippets/toCurrency.md b/snippets/toCurrency.md index 90d77fa51..a89bca3d8 100644 --- a/snippets/toCurrency.md +++ b/snippets/toCurrency.md @@ -1,4 +1,7 @@ -### toCurrency +--- +title: toCurrency +tags: utility,intermediate +--- Take a number and return specified currency formatting. @@ -15,4 +18,4 @@ toCurrency(123456.789, 'USD', 'en-us'); // $123,456.79 | currency: US Dollar | toCurrency(123456.789, 'USD', 'fa'); // ۱۲۳٬۴۵۶٫۷۹ ؜$ | currency: US Dollar | currencyLangFormat: Farsi toCurrency(322342436423.2435, 'JPY'); // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local toCurrency(322342436423.2435, 'JPY', 'fi'); // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish -``` +``` \ No newline at end of file diff --git a/snippets/toDecimalMark.md b/snippets/toDecimalMark.md index 8cf4cd6c8..861875435 100644 --- a/snippets/toDecimalMark.md +++ b/snippets/toDecimalMark.md @@ -1,11 +1,14 @@ -### toDecimalMark +--- +title: toDecimalMark +tags: utility,math,beginner +--- Use `toLocaleString()` to convert a float-point arithmetic to the [Decimal mark](https://en.wikipedia.org/wiki/Decimal_mark) form. It makes a comma separated string from a number. - ```js +```js const toDecimalMark = num => num.toLocaleString('en-US'); ``` ```js toDecimalMark(12305030388.9087); // "12,305,030,388.909" -``` +``` \ No newline at end of file diff --git a/snippets/toHash.md b/snippets/toHash.md index 6ebc38907..c112359d9 100644 --- a/snippets/toHash.md +++ b/snippets/toHash.md @@ -1,4 +1,7 @@ -### toHash +--- +title: toHash +tags: array,intermediate +--- Reduces a given Array-like into a value hash (keyed data store). @@ -27,4 +30,4 @@ managers.forEach( }, toHash(users, 'id'))) ); managers; // [ { manager:1, employees: [ { id: 2, first: "Joe" }, { id: 3, first: "Moe" } ] } ] -``` +``` \ No newline at end of file diff --git a/snippets/toKebabCase.md b/snippets/toKebabCase.md index 4e456982e..0151024f2 100644 --- a/snippets/toKebabCase.md +++ b/snippets/toKebabCase.md @@ -1,4 +1,7 @@ -### toKebabCase +--- +title: toKebabCase +tags: string,regexp,intermediate +--- Converts a string to kebab case. @@ -19,4 +22,4 @@ toKebabCase('some text'); // 'some-text' toKebabCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some-mixed-string-with-spaces-underscores-and-hyphens' toKebabCase('AllThe-small Things'); // "all-the-small-things" toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html" -``` +``` \ No newline at end of file diff --git a/snippets/toOrdinalSuffix.md b/snippets/toOrdinalSuffix.md index 97c866337..28025b5de 100644 --- a/snippets/toOrdinalSuffix.md +++ b/snippets/toOrdinalSuffix.md @@ -1,4 +1,7 @@ -### toOrdinalSuffix +--- +title: toOrdinalSuffix +tags: utility,math,intermediate +--- Adds an ordinal suffix to a number. @@ -21,4 +24,4 @@ const toOrdinalSuffix = num => { ```js toOrdinalSuffix('123'); // "123rd" -``` +``` \ No newline at end of file diff --git a/snippets/toSafeInteger.md b/snippets/toSafeInteger.md index 253778c23..602517cb5 100644 --- a/snippets/toSafeInteger.md +++ b/snippets/toSafeInteger.md @@ -1,4 +1,7 @@ -### toSafeInteger +--- +title: toSafeInteger +tags: math,beginner +--- Converts a value to a safe integer. @@ -13,4 +16,4 @@ const toSafeInteger = num => ```js toSafeInteger('3.2'); // 3 toSafeInteger(Infinity); // 9007199254740991 -``` +``` \ No newline at end of file diff --git a/snippets/toSnakeCase.md b/snippets/toSnakeCase.md index d21d40222..ca135f993 100644 --- a/snippets/toSnakeCase.md +++ b/snippets/toSnakeCase.md @@ -1,4 +1,7 @@ -### toSnakeCase +--- +title: toSnakeCase +tags: string,regexp,intermediate +--- Converts a string to snake case. @@ -19,4 +22,4 @@ toSnakeCase('some text'); // 'some_text' 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('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html" -``` +``` \ No newline at end of file diff --git a/snippets/toTitleCase.md b/snippets/toTitleCase.md index a8739e76a..7ac327749 100644 --- a/snippets/toTitleCase.md +++ b/snippets/toTitleCase.md @@ -1,4 +1,7 @@ -### toTitleCase +--- +title: toTitleCase +tags: string,regepx,intermediate +--- Converts a string to title case. @@ -17,4 +20,4 @@ toTitleCase('some_database_field_name'); // 'Some Database Field Name' toTitleCase('Some label that needs to be title-cased'); // 'Some Label That Needs To Be Title Cased' toTitleCase('some-package-name'); // 'Some Package Name' toTitleCase('some-mixed_string with spaces_underscores-and-hyphens'); // 'Some Mixed String With Spaces Underscores And Hyphens' -``` +``` \ No newline at end of file diff --git a/snippets/toggleClass.md b/snippets/toggleClass.md index eb9f17504..3beb7f574 100644 --- a/snippets/toggleClass.md +++ b/snippets/toggleClass.md @@ -1,4 +1,7 @@ -### toggleClass +--- +title: toggleClass +tags: browser,beginner +--- Toggle a class for an element. @@ -10,4 +13,4 @@ const toggleClass = (el, className) => el.classList.toggle(className); ```js toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore -``` +``` \ No newline at end of file diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md index f7fdccec8..1accbdaca 100644 --- a/snippets/tomorrow.md +++ b/snippets/tomorrow.md @@ -1,4 +1,7 @@ -### tomorrow +--- +title: tomorrow +tags: date,intermediate +--- Results in a string representation of tomorrow's date. @@ -15,4 +18,4 @@ const tomorrow = () => { ```js tomorrow(); // 2018-10-19 (if current date is 2018-10-18) -``` +``` \ No newline at end of file diff --git a/snippets/transform.md b/snippets/transform.md index bd870f3fe..e0e46b4e0 100644 --- a/snippets/transform.md +++ b/snippets/transform.md @@ -1,4 +1,7 @@ -### transform +--- +title: transform +tags: object,array,intermediate +--- Applies a function against an accumulator and each key in the object (from left to right). @@ -17,4 +20,4 @@ transform( }, {} ); // { '1': ['a', 'c'], '2': ['b'] } -``` +``` \ No newline at end of file diff --git a/snippets/triggerEvent.md b/snippets/triggerEvent.md index 113c33df6..719305f29 100644 --- a/snippets/triggerEvent.md +++ b/snippets/triggerEvent.md @@ -1,4 +1,7 @@ -### triggerEvent +--- +title: triggerEvent +tags: browser,event,intermediate +--- Triggers a specific event on a given element, optionally passing custom data. @@ -14,4 +17,4 @@ const triggerEvent = (el, eventType, detail) => ```js triggerEvent(document.getElementById('myId'), 'click'); triggerEvent(document.getElementById('myId'), 'click', { username: 'bob' }); -``` +``` \ No newline at end of file diff --git a/snippets/truncateString.md b/snippets/truncateString.md index 951343be9..d2350fbde 100644 --- a/snippets/truncateString.md +++ b/snippets/truncateString.md @@ -1,4 +1,7 @@ -### truncateString +--- +title: truncateString +tags: string,beginner +--- Truncates a string up to a specified length. @@ -12,4 +15,4 @@ const truncateString = (str, num) => ```js truncateString('boomerang', 7); // 'boom...' -``` +``` \ No newline at end of file diff --git a/snippets/truthCheckCollection.md b/snippets/truthCheckCollection.md index 4ad97358b..6b9716249 100644 --- a/snippets/truthCheckCollection.md +++ b/snippets/truthCheckCollection.md @@ -1,4 +1,7 @@ -### truthCheckCollection +--- +title: truthCheckCollection +tags: object,logic,array,intermediate +--- Checks if the predicate (second argument) is truthy on all elements of a collection (first argument). @@ -10,4 +13,4 @@ const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pr ```js truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex'); // true -``` +``` \ No newline at end of file diff --git a/snippets/unary.md b/snippets/unary.md index 51fa353cc..ed6a66e0a 100644 --- a/snippets/unary.md +++ b/snippets/unary.md @@ -1,4 +1,7 @@ -### unary +--- +title: unary +tags: adapter,function,intermediate +--- Creates a function that accepts up to one argument, ignoring any additional arguments. @@ -10,4 +13,4 @@ const unary = fn => val => fn(val); ```js ['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10] -``` +``` \ No newline at end of file diff --git a/snippets/uncurry.md b/snippets/uncurry.md index 0aa1fdfbc..bc8046cf3 100644 --- a/snippets/uncurry.md +++ b/snippets/uncurry.md @@ -1,4 +1,7 @@ -### uncurry +--- +title: uncurry +tags: function,intermediate +--- Uncurries a function up to depth `n`. @@ -20,4 +23,4 @@ const uncurry = (fn, n = 1) => (...args) => { const add = x => y => z => x + y + z; const uncurriedAdd = uncurry(add, 3); uncurriedAdd(1, 2, 3); // 6 -``` +``` \ No newline at end of file diff --git a/snippets/unescapeHTML.md b/snippets/unescapeHTML.md index 2a6180d18..d2236a8f0 100644 --- a/snippets/unescapeHTML.md +++ b/snippets/unescapeHTML.md @@ -1,4 +1,7 @@ -### unescapeHTML +--- +title: unescapeHTML +tags: string,browser,beginner +--- Unescapes escaped HTML characters. @@ -21,4 +24,4 @@ const unescapeHTML = str => ```js unescapeHTML('<a href="#">Me & you</a>'); // 'Me & you' -``` +``` \ No newline at end of file diff --git a/snippets/unflattenObject.md b/snippets/unflattenObject.md index a37d82070..63859fc98 100644 --- a/snippets/unflattenObject.md +++ b/snippets/unflattenObject.md @@ -1,4 +1,7 @@ -### unflattenObject +--- +title: unflattenObject +tags: object,advanced +--- Unflatten an object with the paths for keys. @@ -27,4 +30,4 @@ const unflattenObject = obj => ```js unflattenObject({ 'a.b.c': 1, d: 1 }); // { a: { b: { c: 1 } }, d: 1 } -``` +``` \ No newline at end of file diff --git a/snippets/unfold.md b/snippets/unfold.md index e16803e73..582185ac2 100644 --- a/snippets/unfold.md +++ b/snippets/unfold.md @@ -1,4 +1,7 @@ -### unfold +--- +title: unfold +tags: function,array,intermediate +--- Builds an array, using an iterator function and an initial seed value. @@ -17,4 +20,4 @@ const unfold = (fn, seed) => { ```js var f = n => (n > 50 ? false : [-n, n + 10]); unfold(f, 10); // [-10, -20, -30, -40, -50] -``` +``` \ No newline at end of file diff --git a/snippets/union.md b/snippets/union.md index bdb6ede2a..479090d31 100644 --- a/snippets/union.md +++ b/snippets/union.md @@ -1,4 +1,7 @@ -### union +--- +title: union +tags: array,math,beginner +--- Returns every element that exists in any of the two arrays once. @@ -10,4 +13,4 @@ const union = (a, b) => Array.from(new Set([...a, ...b])); ```js union([1, 2, 3], [4, 3, 2]); // [1,2,3,4] -``` +``` \ No newline at end of file diff --git a/snippets/unionBy.md b/snippets/unionBy.md index 91c9e6662..2679ea7ab 100644 --- a/snippets/unionBy.md +++ b/snippets/unionBy.md @@ -1,4 +1,7 @@ -### unionBy +--- +title: unionBy +tags: array,function,intermediate +--- Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both. @@ -15,4 +18,4 @@ const unionBy = (a, b, fn) => { ```js unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2] -``` +``` \ No newline at end of file diff --git a/snippets/unionWith.md b/snippets/unionWith.md index f23a079f8..23213789f 100644 --- a/snippets/unionWith.md +++ b/snippets/unionWith.md @@ -1,4 +1,7 @@ -### unionWith +--- +title: unionWith +tags: array,function,intermediate +--- Returns every element that exists in any of the two arrays once, using a provided comparator function. @@ -11,4 +14,4 @@ const unionWith = (a, b, comp) => ```js unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2, 1.5, 3, 0, 3.9] -``` +``` \ No newline at end of file diff --git a/snippets/uniqueElements.md b/snippets/uniqueElements.md index 2d6e557bd..2cf6ebb1d 100644 --- a/snippets/uniqueElements.md +++ b/snippets/uniqueElements.md @@ -1,4 +1,7 @@ -### uniqueElements +--- +title: uniqueElements +tags: array,beginner +--- Returns all unique values of an array. @@ -10,4 +13,4 @@ const uniqueElements = arr => [...new Set(arr)]; ```js uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5] -``` +``` \ No newline at end of file diff --git a/snippets/uniqueElementsBy.md b/snippets/uniqueElementsBy.md index c857f8a48..40f552008 100644 --- a/snippets/uniqueElementsBy.md +++ b/snippets/uniqueElementsBy.md @@ -1,4 +1,7 @@ -### uniqueElementsBy +--- +title: uniqueElementsBy +tags: array,function,intermediate +--- Returns all unique values of an array, based on a provided comparator function. @@ -24,4 +27,4 @@ uniqueElementsBy( ], (a, b) => a.id == b.id ); // [ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ] -``` +``` \ No newline at end of file diff --git a/snippets/uniqueElementsByRight.md b/snippets/uniqueElementsByRight.md index 8d3bbaa7f..59065a037 100644 --- a/snippets/uniqueElementsByRight.md +++ b/snippets/uniqueElementsByRight.md @@ -1,4 +1,7 @@ -### uniqueElementsByRight +--- +title: uniqueElementsByRight +tags: array,function,intermediate +--- Returns all unique values of an array, based on a provided comparator function, starting from the right. @@ -24,4 +27,4 @@ uniqueElementsByRight( ], (a, b) => a.id == b.id ); // [ { id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' } ] -``` +``` \ No newline at end of file diff --git a/snippets/uniqueSymmetricDifference.md b/snippets/uniqueSymmetricDifference.md index cd6c90931..61990fc0d 100644 --- a/snippets/uniqueSymmetricDifference.md +++ b/snippets/uniqueSymmetricDifference.md @@ -1,4 +1,7 @@ -### uniqueSymmetricDifference +--- +title: uniqueSymmetricDifference +tags: array,math,intermediate +--- Returns the unique symmetric difference between two arrays, not containing duplicate values from either array. @@ -13,4 +16,4 @@ const uniqueSymmetricDifference = (a, b) => [ ```js uniqueSymmetricDifference([1, 2, 3], [1, 2, 4]); // [3, 4] uniqueSymmetricDifference([1, 2, 2], [1, 3, 1]); // [2, 3] -``` +``` \ No newline at end of file diff --git a/snippets/untildify.md b/snippets/untildify.md index 8790b0eb4..d3d7c5095 100644 --- a/snippets/untildify.md +++ b/snippets/untildify.md @@ -1,4 +1,7 @@ -### untildify +--- +title: untildify +tags: node,string,beginner +--- Converts a tilde path to an absolute path. @@ -10,4 +13,4 @@ const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$ ```js untildify('~/node'); // '/Users/aUser/node' -``` +``` \ No newline at end of file diff --git a/snippets/unzip.md b/snippets/unzip.md index 003b03fb7..5335959f8 100644 --- a/snippets/unzip.md +++ b/snippets/unzip.md @@ -1,4 +1,7 @@ -### unzip +--- +title: unzip +tags: array,intermediate +--- Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip). @@ -18,4 +21,4 @@ const unzip = arr => ```js unzip([['a', 1, true], ['b', 2, false]]); // [['a', 'b'], [1, 2], [true, false]] unzip([['a', 1, true], ['b', 2]]); // [['a', 'b'], [1, 2], [true]] -``` +``` \ No newline at end of file diff --git a/snippets/unzipWith.md b/snippets/unzipWith.md index 2f64da784..40e5396e4 100644 --- a/snippets/unzipWith.md +++ b/snippets/unzipWith.md @@ -1,4 +1,7 @@ -### unzipWith +--- +title: unzipWith +tags: array,function,advanced +--- Creates an array of elements, ungrouping the elements in an array produced by [zip](#zip) and applying the provided function. @@ -20,4 +23,4 @@ const unzipWith = (arr, fn) => ```js unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)); // [3, 30, 300] -``` +``` \ No newline at end of file diff --git a/snippets/validateNumber.md b/snippets/validateNumber.md index 17a5987d1..ba0047d44 100644 --- a/snippets/validateNumber.md +++ b/snippets/validateNumber.md @@ -1,4 +1,7 @@ -### validateNumber +--- +title: validateNumber +tags: utility,math,intermediate +--- Returns `true` if the given value is a number, `false` otherwise. @@ -12,4 +15,4 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == ```js validateNumber('10'); // true -``` +``` \ No newline at end of file diff --git a/snippets/vectorDistance.md b/snippets/vectorDistance.md index 2a53a14ba..a69bcd352 100644 --- a/snippets/vectorDistance.md +++ b/snippets/vectorDistance.md @@ -1,4 +1,7 @@ -### vectorDistance +--- +title: vectorDistance +tags: math,beginner +--- Returns the distance between two vectors. @@ -16,4 +19,4 @@ const vectorDistance = (...coords) => { ```js vectorDistance(10, 0, 5, 20, 0, 10); // 11.180339887498949 -``` +``` \ No newline at end of file diff --git a/snippets/when.md b/snippets/when.md index b16c7ff32..22a47c997 100644 --- a/snippets/when.md +++ b/snippets/when.md @@ -1,4 +1,7 @@ -### when +--- +title: when +tags: function,intermediate +--- Tests a value, `x`, against a predicate function. If `true`, return `fn(x)`. Else, return `x`. @@ -12,4 +15,4 @@ const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x); const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2); doubleEvenNumbers(2); // 4 doubleEvenNumbers(1); // 1 -``` +``` \ No newline at end of file diff --git a/snippets/without.md b/snippets/without.md index e45fb01a2..e388642dd 100644 --- a/snippets/without.md +++ b/snippets/without.md @@ -1,4 +1,7 @@ -### without +--- +title: without +tags: array,beginner +--- Filters out the elements of an array, that have one of the specified values. @@ -12,4 +15,4 @@ const without = (arr, ...args) => arr.filter(v => !args.includes(v)); ```js without([2, 1, 2, 3], 1, 2); // [3] -``` +``` \ No newline at end of file diff --git a/snippets/words.md b/snippets/words.md index 0637a7d06..f72fdcb68 100644 --- a/snippets/words.md +++ b/snippets/words.md @@ -1,4 +1,7 @@ -### words +--- +title: words +tags: string,regexp,intermediate +--- Converts a given string into an array of words. @@ -12,4 +15,4 @@ const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolea ```js words('I love javaScript!!'); // ["I", "love", "javaScript"] words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"] -``` +``` \ No newline at end of file diff --git a/snippets/xProd.md b/snippets/xProd.md index 85fa68d5a..ba213158e 100644 --- a/snippets/xProd.md +++ b/snippets/xProd.md @@ -1,4 +1,7 @@ -### xProd +--- +title: xProd +tags: array,math,intermediate +--- Creates a new array out of the two supplied by creating each possible pair from the arrays. @@ -10,4 +13,4 @@ const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []) ```js xProd([1, 2], ['a', 'b']); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] -``` +``` \ No newline at end of file diff --git a/snippets/yesNo.md b/snippets/yesNo.md index 5d191cb94..0be6776ed 100644 --- a/snippets/yesNo.md +++ b/snippets/yesNo.md @@ -1,4 +1,7 @@ -### yesNo +--- +title: yesNo +tags: utility,regexp,intermediate +--- Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`. @@ -15,4 +18,4 @@ yesNo('Y'); // true yesNo('yes'); // true yesNo('No'); // false yesNo('Foo', true); // true -``` +``` \ No newline at end of file diff --git a/snippets/yesterday.md b/snippets/yesterday.md index a0a5da5ce..18397afbd 100644 --- a/snippets/yesterday.md +++ b/snippets/yesterday.md @@ -1,4 +1,7 @@ -### yesterday +--- +title: yesterday +tags: date,intermediate +--- Results in a string representation of yesterday's date. @@ -15,4 +18,4 @@ const yesterday = () => { ```js yesterday(); // 2018-10-17 (if current date is 2018-10-18) -``` +``` \ No newline at end of file diff --git a/snippets/zip.md b/snippets/zip.md index d597b4044..bcffbeea7 100644 --- a/snippets/zip.md +++ b/snippets/zip.md @@ -1,4 +1,7 @@ -### zip +--- +title: zip +tags: array,intermediate +--- Creates an array of elements, grouped based on the position in the original arrays. @@ -18,4 +21,4 @@ const zip = (...arrays) => { ```js zip(['a', 'b'], [1, 2], [true, false]); // [['a', 1, true], ['b', 2, false]] zip(['a'], [1, 2], [true, false]); // [['a', 1, true], [undefined, 2, false]] -``` +``` \ No newline at end of file diff --git a/snippets/zipObject.md b/snippets/zipObject.md index e2cda8da3..3de84f2ee 100644 --- a/snippets/zipObject.md +++ b/snippets/zipObject.md @@ -1,4 +1,7 @@ -### zipObject +--- +title: zipObject +tags: array,object,intermediate +--- Given an array of valid property identifiers and an array of values, return an object associating the properties to the values. @@ -12,4 +15,4 @@ const zipObject = (props, values) => ```js zipObject(['a', 'b', 'c'], [1, 2]); // {a: 1, b: 2, c: undefined} zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2} -``` +``` \ No newline at end of file diff --git a/snippets/zipWith.md b/snippets/zipWith.md index 7e4385cbb..4b0b349de 100644 --- a/snippets/zipWith.md +++ b/snippets/zipWith.md @@ -1,4 +1,7 @@ -### zipWith +--- +title: zipWith +tags: array,function,advanced +--- Creates an array of elements, grouped based on the position in the original arrays and using function as the last value to specify how grouped values should be combined. @@ -26,4 +29,4 @@ zipWith( [100, 200], (a, b, c) => (a != null ? a : 'a') + (b != null ? b : 'b') + (c != null ? c : 'c') ); // [111, 222, '3bc'] -``` +``` \ No newline at end of file diff --git a/snippets_archive/JSONToDate.md b/snippets_archive/JSONToDate.md index 421820419..ae88cb2bc 100644 --- a/snippets_archive/JSONToDate.md +++ b/snippets_archive/JSONToDate.md @@ -1,4 +1,7 @@ -### JSONToDate +--- +title: JSONToDate +tags: object,date,beginner +--- Converts a JSON object to a date. @@ -13,4 +16,4 @@ const JSONToDate = arr => { ```js JSONToDate(/Date(1489525200000)/); // "14/3/2017" -``` +``` \ No newline at end of file diff --git a/snippets_archive/README.md b/snippets_archive/README.md index feca993a2..2c10c4262 100644 --- a/snippets_archive/README.md +++ b/snippets_archive/README.md @@ -1,35 +1,7 @@ -![Logo](/logo.png) -# Snippets Archive -These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are. -## Table of Contents -* [`JSONToDate`](#jsontodate) -* [`squareSum`](#squaresum) -* [`binarySearch`](#binarysearch) -* [`celsiusToFahrenheit`](#celsiustofahrenheit) -* [`cleanObj`](#cleanobj) -* [`collatz`](#collatz) -* [`countVowels`](#countvowels) -* [`factors`](#factors) -* [`fahrenheitToCelsius`](#fahrenheittocelsius) -* [`fibonacciCountUntilNum`](#fibonaccicountuntilnum) -* [`fibonacciUntilNum`](#fibonacciuntilnum) -* [`heronArea`](#heronarea) -* [`howManyTimes`](#howmanytimes) -* [`httpPut`](#httpput) -* [`isArmstrongNumber`](#isarmstrongnumber) -* [`isSimilar`](#issimilar) -* [`kmphToMph`](#kmphtomph) -* [`levenshteinDistance`](#levenshteindistance) -* [`mphToKmph`](#mphtokmph) -* [`pipeLog`](#pipelog) -* [`quickSort`](#quicksort) -* [`removeVowels`](#removevowels) -* [`solveRPN`](#solverpn) -* [`speechSynthesis`](#speechsynthesis) -* [`httpDelete`](#httpdelete) - --- -### JSONToDate +title: README +tags: +--- Converts a JSON object to a date. @@ -42,721 +14,6 @@ const JSONToDate = arr => { }; ``` -
    -Examples - ```js JSONToDate(/Date(1489525200000)/); // "14/3/2017" -``` - -
    - -
    [⬆ Back to top](#contents) - -### squareSum - -Squares each number in an array and then sums the results together. - -Use `Array.prototype.reduce()` in combination with `Math.pow()` to iterate over numbers and sum their squares into an accumulator. - -```js -const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0); -``` - -
    -Examples - -```js -squareSum(1, 2, 2); // 9 -``` - -
    - -
    [⬆ Back to top](#contents) - -### binarySearch - -Use recursion. Similar to `Array.prototype.indexOf()` that finds the index of a value within an array. -The 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()`. - -Search a sorted array by repeatedly dividing the search interval in half. -Begin with an interval covering the whole array. -If 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. -Repeatedly 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`. - -```js -const binarySearch = (arr, val, start = 0, end = arr.length - 1) => { - if (start > end) return -1; - const mid = Math.floor((start + end) / 2); - if (arr[mid] > val) return binarySearch(arr, val, start, mid - 1); - if (arr[mid] < val) return binarySearch(arr, val, mid + 1, end); - return mid; -}; -``` - -
    -Examples - -```js -binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6); // 2 -binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1 -``` - -
    - -
    [⬆ Back to top](#contents) - -### celsiusToFahrenheit - -Celsius to Fahrenheit temperature conversion. - -Follows the conversion formula `F = 1.8C + 32`. - -```js -const celsiusToFahrenheit = degrees => 1.8 * degrees + 32; -``` - -
    -Examples - -```js -celsiusToFahrenheit(33) // 91.4 -``` - -
    - -
    [⬆ Back to top](#contents) - -### cleanObj - -Removes any properties except the ones specified from a JSON object. - -Use `Object.keys()` method to loop over given JSON object and deleting keys that are not included in given array. -If you pass a special key,`childIndicator`, it will search deeply apply the function to inner objects, too. - -```js -const cleanObj = (obj, keysToKeep = [], childIndicator) => { - Object.keys(obj).forEach(key => { - if (key === childIndicator) { - cleanObj(obj[key], keysToKeep, childIndicator); - } else if (!keysToKeep.includes(key)) { - delete obj[key]; - } - }); - return obj; -}; -``` - -
    -Examples - -```js -const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; -cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}} -``` - -
    - -
    [⬆ Back to top](#contents) - -### collatz - -Applies the Collatz algorithm. - -If `n` is even, return `n/2`. Otherwise, return `3n+1`. - -```js -const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1); -``` - -
    -Examples - -```js -collatz(8); // 4 -``` - -
    - -
    [⬆ Back to top](#contents) - -### countVowels - -Retuns `number` of vowels in provided string. - -Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a `string`. - -```js -const countVowels = str => (str.match(/[aeiou]/gi) || []).length; -``` - -
    -Examples - -```js -countVowels('foobar'); // 3 -countVowels('gym'); // 0 -``` - -
    - -
    [⬆ Back to top](#contents) - -### factors - -Returns the array of factors of the given `num`. -If the second argument is set to `true` returns only the prime factors of `num`. -If `num` is `1` or `0` returns an empty array. -If `num` is less than `0` returns all the factors of `-int` together with their additive inverses. - -Use `Array.from()`, `Array.prototype.map()` and `Array.prototype.filter()` to find all the factors of `num`. -If given `num` is negative, use `Array.prototype.reduce()` to add the additive inverses to the array. -Return all results if `primes` is `false`, else determine and return only the prime factors using `isPrime` and `Array.prototype.filter()`. -Omit the second argument, `primes`, to return prime and non-prime factors by default. - -**Note**:- _Negative numbers are not considered prime._ - -```js -const factors = (num, primes = false) => { - const isPrime = num => { - const boundary = Math.floor(Math.sqrt(num)); - for (var i = 2; i <= boundary; i++) if (num % i === 0) return false; - return num >= 2; - }; - const isNeg = num < 0; - num = isNeg ? -num : num; - let array = Array.from({ length: num - 1 }) - .map((val, i) => (num % (i + 2) === 0 ? i + 2 : false)) - .filter(val => val); - if (isNeg) - array = array.reduce((acc, val) => { - acc.push(val); - acc.push(-val); - return acc; - }, []); - return primes ? array.filter(isPrime) : array; -}; -``` - -
    -Examples - -```js -factors(12); // [2,3,4,6,12] -factors(12, true); // [2,3] -factors(-12); // [2, -2, 3, -3, 4, -4, 6, -6, 12, -12] -factors(-12, true); // [2,3] -``` - -
    - -
    [⬆ Back to top](#contents) - -### fahrenheitToCelsius - -Fahrenheit to Celsius temperature conversion. - -Follows the conversion formula `C = (F - 32) * 5/9`. - -```js -const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9; -``` - -
    -Examples - -```js -fahrenheitToCelsius(32); // 0 -``` - -
    - -
    [⬆ Back to top](#contents) - -### fibonacciCountUntilNum - -Returns the number of fibonnacci numbers up to `num`(`0` and `num` inclusive). - -Use a mathematical formula to calculate the number of fibonacci numbers until `num`. - -```js -const fibonacciCountUntilNum = num => - Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2)); -``` - -
    -Examples - -```js -fibonacciCountUntilNum(10); // 7 -``` - -
    - -
    [⬆ Back to top](#contents) - -### fibonacciUntilNum - -Generates an array, containing the Fibonacci sequence, up until the nth term. - -Create an empty array of the specific length, initializing the first two values (`0` and `1`). -Use `Array.prototype.reduce()` to add values into the array, using the sum of the last two values, except for the first two. -Uses a mathematical formula to calculate the length of the array required. - -```js -const fibonacciUntilNum = num => { - let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2)); - return Array.from({ length: n }).reduce( - (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), - [] - ); -}; -``` - -
    -Examples - -```js -fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ] -``` - -
    - -
    [⬆ Back to top](#contents) - -### heronArea - -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. - -More information on what Heron's formula is and why it works available here: https://en.wikipedia.org/wiki/Heron%27s_formula. - -Uses `Math.sqrt()` to find the square root of a value. - - -```js -const heronArea = (side_a, side_b, side_c) => { - const p = (side_a + side_b + side_c) / 2 - return Math.sqrt(p * (p-side_a) * (p-side_b) * (p-side_c)) - }; -``` - -
    -Examples - -```js -heronArea(3, 4, 5); // 6 -``` - -
    - -
    [⬆ Back to top](#contents) - -### howManyTimes - -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. - -If `divisor` is `-1` or `1` return `Infinity`. -If `divisor` is `-0` or `0` return `0`. -Otherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer. -Return the number of times the loop was executed, `i`. - -```js -const howManyTimes = (num, divisor) => { - if (divisor === 1 || divisor === -1) return Infinity; - if (divisor === 0) return 0; - let i = 0; - while (Number.isInteger(num / divisor)) { - i++; - num = num / divisor; - } - return i; -}; -``` - -
    -Examples - -```js -howManyTimes(100, 2); // 2 -howManyTimes(100, 2.5); // 2 -howManyTimes(100, 0); // 0 -howManyTimes(100, -1); // Infinity -``` - -
    - -
    [⬆ Back to top](#contents) - -### httpPut - -Makes a `PUT` request to the passed URL. - -Use `XMLHttpRequest` web api to make a `put` request to the given `url`. -Set the value of an `HTTP` request header with `setRequestHeader` method. -Handle the `onload` event, by running the provided `callback` function. -Handle the `onerror` event, by running the provided `err` function. -Omit the last argument, `err` to log the request to the console's error stream by default. - -```js -const httpPut = (url, data, callback, err = console.error) => { - const request = new XMLHttpRequest(); - request.open("PUT", url, true); - request.setRequestHeader('Content-type','application/json; charset=utf-8'); - request.onload = () => callback(request); - request.onerror = () => err(request); - request.send(data); -}; -``` - -
    -Examples - -```js -const password = "fooBaz"; -const data = JSON.stringify(password); -httpPut('https://website.com/users/123', data, request => { - console.log(request.responseText); -}); // 'Updates a user's password in database' -``` - -
    - -
    [⬆ Back to top](#contents) - -### isArmstrongNumber - -Checks if the given number is an Armstrong number or not. - -Convert 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`. - -```js -const isArmstrongNumber = digits => - (arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)( - (digits + '').split('') - ); -``` - -
    -Examples - -```js -isArmstrongNumber(1634); // true -isArmstrongNumber(56); // false -``` - -
    - -
    [⬆ Back to top](#contents) - -### isSimilar - -Determines if the `pattern` matches with `str`. - -Use `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. -Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db53428247e741b9efe2cde9667050c/code/fts_fuzzy_match.js#L18). - -```js -const isSimilar = (pattern, str) => - [...str].reduce( - (matchIndex, char) => - char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() - ? matchIndex + 1 - : matchIndex, - 0 - ) === pattern.length; -``` - -
    -Examples - -```js -isSimilar('rt','Rohit'); // true -isSimilar('tr','Rohit'); // false -``` - -
    - -
    [⬆ Back to top](#contents) - -### kmphToMph - -Convert kilometers/hour to miles/hour. - -Multiply the constant of proportionality with the argument. - -```js -const kmphToMph = (kmph) => 0.621371192 * kmph; -``` - -
    -Examples - -```js -kmphToMph(10); // 16.09344000614692 -kmphToMph(345.4); // 138.24264965280207 -``` - -
    - -
    [⬆ Back to top](#contents) - -### levenshteinDistance - -Calculates the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings. - -Calculates the number of changes (substitutions, deletions or additions) required to convert `string1` to `string2`. -Can also be used to compare two strings as shown in the second example. - -```js -const levenshteinDistance = (string1, string2) => { - if (string1.length === 0) return string2.length; - if (string2.length === 0) return string1.length; - let matrix = Array(string2.length + 1) - .fill(0) - .map((x, i) => [i]); - matrix[0] = Array(string1.length + 1) - .fill(0) - .map((x, i) => i); - for (let i = 1; i <= string2.length; i++) { - for (let j = 1; j <= string1.length; j++) { - if (string2[i - 1] === string1[j - 1]) { - matrix[i][j] = matrix[i - 1][j - 1]; - } else { - matrix[i][j] = Math.min( - matrix[i - 1][j - 1] + 1, - matrix[i][j - 1] + 1, - matrix[i - 1][j] + 1 - ); - } - } - } - return matrix[string2.length][string1.length]; -}; -``` - -
    -Examples - -```js -levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7 -const compareStrings = (string1,string2) => (100 - levenshteinDistance(string1,string2) / Math.max(string1.length,string2.length)); -compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%) -``` - -
    - -
    [⬆ Back to top](#contents) - -### mphToKmph - -Convert miles/hour to kilometers/hour. - -Multiply the constant of proportionality with the argument. - -```js -const mphToKmph = (mph) => 1.6093440006146922 * mph; -``` - -
    -Examples - -```js -mphToKmph(10); // 16.09344000614692 -mphToKmph(85.9); // 138.24264965280207 -``` - -
    - -
    [⬆ Back to top](#contents) - -### pipeLog - -Logs a value and returns it. - -Use `console.log` to log the supplied value, combined with the `||` operator to return it. - - - -```js -const pipeLog = data => console.log(data) || data; -``` - -
    -Examples - -```js -pipeLog(1); // logs `1` and returns `1` -``` - -
    - -
    [⬆ Back to top](#contents) - -### quickSort - -QuickSort an Array (ascending sort by default). - -Use recursion. -Use `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. -If the parameter `desc` is truthy, return array sorts in descending order. - -```js -const quickSort = ([n, ...nums], desc) => - isNaN(n) - ? [] - : [ - ...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc), - n, - ...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc) - ]; -``` - -
    -Examples - -```js -quickSort([4, 1, 3, 2]); // [1,2,3,4] -quickSort([4, 1, 3, 2], true); // [4,3,2,1] -``` - -
    - -
    [⬆ Back to top](#contents) - -### removeVowels - -Returns all the vowels in a `str` replaced by `repl`. - -Use `String.prototype.replace()` with a regexp to replace all vowels in `str`. -Omot `repl` to use a default value of `''`. - -```js -const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl); -``` - -
    -Examples - -```js -removeVowels("foobAr"); // "fbr" -removeVowels("foobAr","*"); // "f**b*r" -``` - -
    - -
    [⬆ Back to top](#contents) - -### solveRPN - -Solves the given mathematical expression in [reverse polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation). -Throws 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. - -Use a dictionary, `OPERATORS` to specify each operator's matching mathematical operation. -Use `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. -Use `Array.prototype.forEach()` to parse each `symbol`, evaluate it as a numeric value or operator and solve the mathematical expression. -Numeric 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. - -```js -const solveRPN = rpn => { - const OPERATORS = { - '*': (a, b) => a * b, - '+': (a, b) => a + b, - '-': (a, b) => a - b, - '/': (a, b) => a / b, - '**': (a, b) => a ** b - }; - const [stack, solve] = [ - [], - rpn - .replace(/\^/g, '**') - .split(/\s+/g) - .filter(el => !/\s+/.test(el) && el !== '') - ]; - solve.forEach(symbol => { - if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) { - stack.push(symbol); - } else if (Object.keys(OPERATORS).includes(symbol)) { - const [a, b] = [stack.pop(), stack.pop()]; - stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a))); - } else { - throw `${symbol} is not a recognized symbol`; - } - }); - if (stack.length === 1) return stack.pop(); - else throw `${rpn} is not a proper RPN. Please check it and try again`; -}; -``` - -
    -Examples - -```js -solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5 -solveRPN('2 3 ^'); // 8 -``` - -
    - -
    [⬆ Back to top](#contents) - -### speechSynthesis - -Performs speech synthesis (experimental). - -Use `SpeechSynthesisUtterance.voice` and `window.speechSynthesis.getVoices()` to convert a message to speech. -Use `window.speechSynthesis.speak()` to play the message. - -Learn more about the [SpeechSynthesisUtterance interface of the Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance). - -```js -const speechSynthesis = message => { - const msg = new SpeechSynthesisUtterance(message); - msg.voice = window.speechSynthesis.getVoices()[0]; - window.speechSynthesis.speak(msg); -}; -``` - -
    -Examples - -```js -speechSynthesis('Hello, World'); // // plays the message -``` - -
    - -
    [⬆ Back to top](#contents) - -### httpDelete - -Makes a `DELETE` request to the passed URL. - -Use `XMLHttpRequest` web api to make a `delete` request to the given `url`. -Handle the `onload` event, by running the provided `callback` function. -Handle the `onerror` event, by running the provided `err` function. -Omit the third argument, `err` to log the request to the console's error stream by default. - -```js -const httpDelete = (url, callback, err = console.error) => { - const request = new XMLHttpRequest(); - request.open('DELETE', url, true); - request.onload = () => callback(request); - request.onerror = () => err(request); - request.send(); -}; -``` - -
    -Examples - -```js -httpDelete('https://website.com/users/123', request => { - console.log(request.responseText); -}); // 'Deletes a user from the database' -``` - -
    - -
    [⬆ Back to top](#contents) - +``` \ No newline at end of file diff --git a/snippets_archive/binarySearch.md b/snippets_archive/binarySearch.md index 0b94b3147..c68b19b87 100644 --- a/snippets_archive/binarySearch.md +++ b/snippets_archive/binarySearch.md @@ -1,4 +1,7 @@ -### binarySearch +--- +title: binarySearch +tags: algorithm,beginner +--- Use recursion. Similar to `Array.prototype.indexOf()` that finds the index of a value within an array. The 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()`. @@ -21,4 +24,4 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => { ```js binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6); // 2 binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1 -``` +``` \ No newline at end of file diff --git a/snippets_archive/celsiusToFahrenheit.md b/snippets_archive/celsiusToFahrenheit.md index 2d7a8e370..486f1f2e4 100644 --- a/snippets_archive/celsiusToFahrenheit.md +++ b/snippets_archive/celsiusToFahrenheit.md @@ -1,4 +1,7 @@ -### celsiusToFahrenheit +--- +title: celsiusToFahrenheit +tags: math,beginner +--- Celsius to Fahrenheit temperature conversion. @@ -10,4 +13,4 @@ const celsiusToFahrenheit = degrees => 1.8 * degrees + 32; ```js celsiusToFahrenheit(33) // 91.4 -``` +``` \ No newline at end of file diff --git a/snippets_archive/cleanObj.md b/snippets_archive/cleanObj.md index e068deb10..40956a51a 100644 --- a/snippets_archive/cleanObj.md +++ b/snippets_archive/cleanObj.md @@ -1,4 +1,7 @@ -### cleanObj +--- +title: cleanObj +tags: object,beginner +--- Removes any properties except the ones specified from a JSON object. @@ -21,4 +24,4 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => { ```js const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}} -``` +``` \ No newline at end of file diff --git a/snippets_archive/collatz.md b/snippets_archive/collatz.md index 998039a5e..a2b764087 100644 --- a/snippets_archive/collatz.md +++ b/snippets_archive/collatz.md @@ -1,4 +1,7 @@ -### collatz +--- +title: collatz +tags: math,beginner +--- Applies the Collatz algorithm. @@ -10,4 +13,4 @@ const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1); ```js collatz(8); // 4 -``` +``` \ No newline at end of file diff --git a/snippets_archive/countVowels.md b/snippets_archive/countVowels.md index b19772731..77a593853 100644 --- a/snippets_archive/countVowels.md +++ b/snippets_archive/countVowels.md @@ -1,4 +1,7 @@ -### countVowels +--- +title: countVowels +tags: string,beginner +--- Retuns `number` of vowels in provided string. @@ -11,4 +14,4 @@ const countVowels = str => (str.match(/[aeiou]/gi) || []).length; ```js countVowels('foobar'); // 3 countVowels('gym'); // 0 -``` +``` \ No newline at end of file diff --git a/snippets_archive/factors.md b/snippets_archive/factors.md index 9ac17d453..0605a6ea1 100644 --- a/snippets_archive/factors.md +++ b/snippets_archive/factors.md @@ -1,4 +1,7 @@ -### factors +--- +title: factors +tags: math,intermediate +--- Returns the array of factors of the given `num`. If the second argument is set to `true` returns only the prime factors of `num`. @@ -39,4 +42,4 @@ factors(12); // [2,3,4,6,12] factors(12, true); // [2,3] factors(-12); // [2, -2, 3, -3, 4, -4, 6, -6, 12, -12] factors(-12, true); // [2,3] -``` +``` \ No newline at end of file diff --git a/snippets_archive/fahrenheitToCelsius.md b/snippets_archive/fahrenheitToCelsius.md index 5a94518b3..0b2d9d186 100644 --- a/snippets_archive/fahrenheitToCelsius.md +++ b/snippets_archive/fahrenheitToCelsius.md @@ -1,4 +1,7 @@ -### fahrenheitToCelsius +--- +title: fahrenheitToCelsius +tags: math,beginner +--- Fahrenheit to Celsius temperature conversion. @@ -10,4 +13,4 @@ const fahrenheitToCelsius = degrees => (degrees - 32) * 5/9; ```js fahrenheitToCelsius(32); // 0 -``` +``` \ No newline at end of file diff --git a/snippets_archive/fibonacciCountUntilNum.md b/snippets_archive/fibonacciCountUntilNum.md index 43f277daf..e3cc779b4 100644 --- a/snippets_archive/fibonacciCountUntilNum.md +++ b/snippets_archive/fibonacciCountUntilNum.md @@ -1,4 +1,7 @@ -### fibonacciCountUntilNum +--- +title: fibonacciCountUntilNum +tags: math,beginner +--- Returns the number of fibonnacci numbers up to `num`(`0` and `num` inclusive). @@ -11,4 +14,4 @@ const fibonacciCountUntilNum = num => ```js fibonacciCountUntilNum(10); // 7 -``` +``` \ No newline at end of file diff --git a/snippets_archive/fibonacciUntilNum.md b/snippets_archive/fibonacciUntilNum.md index 069d34f9b..f4f04ef90 100644 --- a/snippets_archive/fibonacciUntilNum.md +++ b/snippets_archive/fibonacciUntilNum.md @@ -1,4 +1,7 @@ -### fibonacciUntilNum +--- +title: fibonacciUntilNum +tags: math,intermediate +--- Generates an array, containing the Fibonacci sequence, up until the nth term. @@ -18,4 +21,4 @@ const fibonacciUntilNum = num => { ```js fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ] -``` +``` \ No newline at end of file diff --git a/snippets_archive/heronArea.md b/snippets_archive/heronArea.md index 71224b8f7..1be742986 100644 --- a/snippets_archive/heronArea.md +++ b/snippets_archive/heronArea.md @@ -1,4 +1,7 @@ -### heronArea +--- +title: heronArea +tags: math,beginner +--- 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. @@ -6,7 +9,6 @@ More information on what Heron's formula is and why it works available here: htt Uses `Math.sqrt()` to find the square root of a value. - ```js const heronArea = (side_a, side_b, side_c) => { const p = (side_a + side_b + side_c) / 2 @@ -16,4 +18,4 @@ const heronArea = (side_a, side_b, side_c) => { ```js heronArea(3, 4, 5); // 6 -``` +``` \ No newline at end of file diff --git a/snippets_archive/howManyTimes.md b/snippets_archive/howManyTimes.md index 1892d9261..e0569e0bf 100644 --- a/snippets_archive/howManyTimes.md +++ b/snippets_archive/howManyTimes.md @@ -1,4 +1,7 @@ -### howManyTimes +--- +title: howManyTimes +tags: math,beginner +--- 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. @@ -26,4 +29,4 @@ howManyTimes(100, 2); // 2 howManyTimes(100, 2.5); // 2 howManyTimes(100, 0); // 0 howManyTimes(100, -1); // Infinity -``` +``` \ No newline at end of file diff --git a/snippets_archive/httpDelete.md b/snippets_archive/httpDelete.md index 0b95fd2ff..5552a25ae 100644 --- a/snippets_archive/httpDelete.md +++ b/snippets_archive/httpDelete.md @@ -1,4 +1,7 @@ -### httpDelete +--- +title: httpDelete +tags: browser,intermediate +--- Makes a `DELETE` request to the passed URL. @@ -21,4 +24,4 @@ const httpDelete = (url, callback, err = console.error) => { httpDelete('https://website.com/users/123', request => { console.log(request.responseText); }); // 'Deletes a user from the database' -``` +``` \ No newline at end of file diff --git a/snippets_archive/httpPut.md b/snippets_archive/httpPut.md index 400f5dcd3..14488f79d 100644 --- a/snippets_archive/httpPut.md +++ b/snippets_archive/httpPut.md @@ -1,4 +1,7 @@ -### httpPut +--- +title: httpPut +tags: browser,intermediate +--- Makes a `PUT` request to the passed URL. @@ -25,4 +28,4 @@ const data = JSON.stringify(password); httpPut('https://website.com/users/123', data, request => { console.log(request.responseText); }); // 'Updates a user's password in database' -``` +``` \ No newline at end of file diff --git a/snippets_archive/isArmstrongNumber.md b/snippets_archive/isArmstrongNumber.md index 63b6a9afa..96c3b205d 100644 --- a/snippets_archive/isArmstrongNumber.md +++ b/snippets_archive/isArmstrongNumber.md @@ -1,4 +1,7 @@ -### isArmstrongNumber +--- +title: isArmstrongNumber +tags: math,beginner +--- Checks if the given number is an Armstrong number or not. @@ -14,4 +17,4 @@ const isArmstrongNumber = digits => ```js isArmstrongNumber(1634); // true isArmstrongNumber(56); // false -``` +``` \ No newline at end of file diff --git a/snippets_archive/isSimilar.md b/snippets_archive/isSimilar.md index 7bb1b6745..785ab130e 100644 --- a/snippets_archive/isSimilar.md +++ b/snippets_archive/isSimilar.md @@ -1,4 +1,7 @@ -### isSimilar +--- +title: isSimilar +tags: string,intermediate +--- Determines if the `pattern` matches with `str`. @@ -19,4 +22,4 @@ const isSimilar = (pattern, str) => ```js isSimilar('rt','Rohit'); // true isSimilar('tr','Rohit'); // false -``` +``` \ No newline at end of file diff --git a/snippets_archive/kmphToMph.md b/snippets_archive/kmphToMph.md index 14422bb15..36685e1f7 100644 --- a/snippets_archive/kmphToMph.md +++ b/snippets_archive/kmphToMph.md @@ -1,4 +1,7 @@ -### kmphToMph +--- +title: kmphToMph +tags: math,beginner +--- Convert kilometers/hour to miles/hour. @@ -11,4 +14,4 @@ const kmphToMph = (kmph) => 0.621371192 * kmph; ```js kmphToMph(10); // 16.09344000614692 kmphToMph(345.4); // 138.24264965280207 -``` +``` \ No newline at end of file diff --git a/snippets_archive/levenshteinDistance.md b/snippets_archive/levenshteinDistance.md index 959c27806..646adc298 100644 --- a/snippets_archive/levenshteinDistance.md +++ b/snippets_archive/levenshteinDistance.md @@ -1,4 +1,7 @@ -### levenshteinDistance +--- +title: levenshteinDistance +tags: algorithm,advanced +--- Calculates the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings. @@ -36,4 +39,4 @@ const levenshteinDistance = (string1, string2) => { levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7 const compareStrings = (string1,string2) => (100 - levenshteinDistance(string1,string2) / Math.max(string1.length,string2.length)); compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%) -``` +``` \ No newline at end of file diff --git a/snippets_archive/mphToKmph.md b/snippets_archive/mphToKmph.md index 4d898709e..6d0eb6e5f 100644 --- a/snippets_archive/mphToKmph.md +++ b/snippets_archive/mphToKmph.md @@ -1,4 +1,7 @@ -### mphToKmph +--- +title: mphToKmph +tags: math,beginner +--- Convert miles/hour to kilometers/hour. @@ -11,4 +14,4 @@ const mphToKmph = (mph) => 1.6093440006146922 * mph; ```js mphToKmph(10); // 16.09344000614692 mphToKmph(85.9); // 138.24264965280207 -``` +``` \ No newline at end of file diff --git a/snippets_archive/pipeLog.md b/snippets_archive/pipeLog.md index 972776b1f..5623b465f 100644 --- a/snippets_archive/pipeLog.md +++ b/snippets_archive/pipeLog.md @@ -1,15 +1,16 @@ -### pipeLog +--- +title: pipeLog +tags: utility,beginner +--- Logs a value and returns it. Use `console.log` to log the supplied value, combined with the `||` operator to return it. - - ```js const pipeLog = data => console.log(data) || data; ``` ```js pipeLog(1); // logs `1` and returns `1` -``` +``` \ No newline at end of file diff --git a/snippets_archive/quickSort.md b/snippets_archive/quickSort.md index a080559f4..6b2a58e1a 100644 --- a/snippets_archive/quickSort.md +++ b/snippets_archive/quickSort.md @@ -1,4 +1,7 @@ -### quickSort +--- +title: quickSort +tags: algorithm,recursion,beginner +--- QuickSort an Array (ascending sort by default). @@ -20,4 +23,4 @@ const quickSort = ([n, ...nums], desc) => ```js quickSort([4, 1, 3, 2]); // [1,2,3,4] quickSort([4, 1, 3, 2], true); // [4,3,2,1] -``` +``` \ No newline at end of file diff --git a/snippets_archive/removeVowels.md b/snippets_archive/removeVowels.md index 2416d446b..f7fb45896 100644 --- a/snippets_archive/removeVowels.md +++ b/snippets_archive/removeVowels.md @@ -1,4 +1,7 @@ -### removeVowels +--- +title: removeVowels +tags: string,beginner +--- Returns all the vowels in a `str` replaced by `repl`. @@ -12,4 +15,4 @@ const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl); ```js removeVowels("foobAr"); // "fbr" removeVowels("foobAr","*"); // "f**b*r" -``` +``` \ No newline at end of file diff --git a/snippets_archive/solveRPN.md b/snippets_archive/solveRPN.md index f01f98078..2bca5d81b 100644 --- a/snippets_archive/solveRPN.md +++ b/snippets_archive/solveRPN.md @@ -1,4 +1,7 @@ -### solveRPN +--- +title: solveRPN +tags: algorithm,advanced +--- Solves the given mathematical expression in [reverse polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation). Throws 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. @@ -42,4 +45,4 @@ const solveRPN = rpn => { ```js solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5 solveRPN('2 3 ^'); // 8 -``` +``` \ No newline at end of file diff --git a/snippets_archive/speechSynthesis.md b/snippets_archive/speechSynthesis.md index ccad3f636..18f2229f8 100644 --- a/snippets_archive/speechSynthesis.md +++ b/snippets_archive/speechSynthesis.md @@ -1,4 +1,7 @@ -### speechSynthesis +--- +title: speechSynthesis +tags: browser,intermediate +--- Performs speech synthesis (experimental). @@ -17,4 +20,4 @@ const speechSynthesis = message => { ```js speechSynthesis('Hello, World'); // // plays the message -``` +``` \ No newline at end of file diff --git a/snippets_archive/squareSum.md b/snippets_archive/squareSum.md index 326504b40..af17a6c2e 100644 --- a/snippets_archive/squareSum.md +++ b/snippets_archive/squareSum.md @@ -1,4 +1,7 @@ -### squareSum +--- +title: squareSum +tags: math,beginner +--- Squares each number in an array and then sums the results together. @@ -10,4 +13,4 @@ const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Ma ```js squareSum(1, 2, 2); // 9 -``` +``` \ No newline at end of file diff --git a/tag_database b/tag_database deleted file mode 100644 index 355c34070..000000000 --- a/tag_database +++ /dev/null @@ -1,350 +0,0 @@ -all:array,function,beginner -allEqual:array,function,beginner -any:array,function,beginner -approximatelyEqual:math,beginner -arrayToCSV:array,string,utility,intermediate -arrayToHtmlList:browser,array,intermediate -ary:adapter,function,intermediate -atob:node,string,utility,beginner -attempt:function,intermediate -average:math,array,beginner -averageBy:math,array,function,intermediate -bifurcate:array,intermediate -bifurcateBy:array,function,intermediate -bind:function,object,intermediate -bindAll:object,function,intermediate -bindKey:function,object,intermediate -binomialCoefficient:math,intermediate -bottomVisible:browser,intermediate -btoa:node,string,utility,beginner -byteSize:string,beginner -call:adapter,function,intermediate -capitalize:string,array,intermediate -capitalizeEveryWord:string,regexp,intermediate -castArray:utility,array,type,beginner -chainAsync:function,intermediate -checkProp:function,object,utility,beginner -chunk:array,intermediate -clampNumber:math,beginner -cloneRegExp:utility,regexp,intermediate -coalesce:utility,beginner -coalesceFactory:utility,intermediate -collectInto:adapter,function,array,intermediate -colorize:node,utility,string,intermediate -compact:array,beginner -compactWhitespace:string,regexp,beginner -compose:function,intermediate -composeRight:function,intermediate -converge:function,intermediate -copyToClipboard:browser,string,advanced -countBy:array,object,intermediate -counter:browser,advanced -countOccurrences:array,intermediate -createDirIfNotExists:node,beginner -createElement:browser,utility,beginner -createEventHub:browser,event,advanced -CSVToArray:string,array,utility,intermediate -CSVToJSON:string,array,object,advanced -currentURL:browser,url,beginner -curry:function,recursion,intermediate -dayOfYear:date,beginner -debounce:function,intermediate -decapitalize:string,array,intermediate -deepClone:object,recursion,intermediate -deepFlatten:array,recursion,intermediate -deepFreeze:object,recursion,intermediate -deepGet:object,intermediate -deepMapKeys:object,recursion,advanced -defaults:object,intermediate -defer:function,intermediate -degreesToRads:math,beginner -delay:function,intermediate -detectDeviceType:browser,intermediate -difference:array,math,beginner -differenceBy:array,function,intermediate -differenceWith:array,function,intermediate -dig:object,recursion,intermediate -digitize:math,array,beginner -distance:math,beginner -drop:array,beginner -dropRight:array,beginner -dropRightWhile:array,function,intermediate -dropWhile:array,function,intermediate -elementContains:browser,intermediate -elementIsVisibleInViewport:browser,advanced -elo:math,array,advanced -equals:object,array,type,advanced -escapeHTML:string,browser,regexp,intermediate -escapeRegExp:string,regexp,intermediate -everyNth:array,beginner -extendHex:utility,string,intermediate -factorial:math,recursion,beginner -fibonacci:math,array,beginner -filterFalsy:array,beginner -filterNonUnique:array,beginner -filterNonUniqueBy:array,function,intermediate -findKey:object,function,intermediate -findLast:array,beginner -findLastIndex:array,function,intermediate -findLastKey:object,function,intermediate -flatten:array,intermediate -flattenObject:object,recursion,intermediate -flip:adapter,function,intermediate -forEachRight:array,function,intermediate -formatDuration:date,math,string,utility,intermediate -formToObject:browser,object,intermediate -forOwn:object,intermediate -forOwnRight:object,intermediate -fromCamelCase:string,intermediate -functionName:function,utility,beginner -functions:object,function,intermediate -gcd:math,recursion,beginner -geometricProgression:math,intermediate -get:object,intermediate -getColonTimeFromDate:date,intermediate -getDaysDiffBetweenDates:date,intermediate -getImages:browser,beginner -getMeridiemSuffixOfInteger:date,beginner -getScrollPosition:browser,intermediate -getStyle:browser,css,beginner -getType:type,beginner -getURLParameters:utility,browser,string,url,intermediate -groupBy:array,object,intermediate -hammingDistance:math,beginner -hasClass:browser,css,beginner -hasFlags:node,intermediate -hashBrowser:browser,utility,advanced,promise,advanced -hashNode:node,utility,promise,intermediate -head:array,beginner -hexToRGB:utility,string,math,advanced -hide:browser,css,beginner -httpGet:utility,url,browser,intermediate -httpPost:utility,url,browser,intermediate -httpsRedirect:browser,url,intermediate -hz:function,intermediate -indentString:string,utility,beginner -indexOfAll:array,intermediate -initial:array,beginner -initialize2DArray:array,intermediate -initializeArrayWithRange:array,math,intermediate -initializeArrayWithRangeRight:array,math,intermediate -initializeArrayWithValues:array,math,intermediate -initializeNDArray:array,recursion,intermediate -inRange:math,beginner -insertAfter:browser,beginner -insertBefore:browser,beginner -intersection:array,math,intermediate -intersectionBy:array,function,intermediate -intersectionWith:array,function,intermediate -invertKeyValues:object,function,intermediate -is:type,array,regexp,beginner -isAbsoluteURL:string,utility,browser,url,intermediate -isAfterDate:date,utility,beginner -isAnagram:string,regexp,intermediate -isArrayLike:type,array,intermediate -isBeforeDate:date,utility,beginner -isBoolean:type,beginner -isBrowser:utility,browser,intermediate -isBrowserTabFocused:browser,beginner -isDivisible:math,beginner -isDuplexStream:node,type,intermediate -isEmpty:type,array,object,string,beginner -isEven:math,beginner -isFunction:type,function,beginner -isLowerCase:string,utility,beginner -isNegativeZero:math,utility,beginner -isNil:type,beginner -isNull:type,beginner -isNumber:type,math,beginner -isObject:type,object,beginner -isObjectLike:type,object,beginner -isPlainObject:type,object,intermediate -isPrime:math,beginner,intermediate -isPrimitive:type,function,array,string,intermediate -isPromiseLike:type,function,promise,intermediate -isReadableStream:node,type,intermediate -isSameDate:date,utility,beginner -isSorted:array,intermediate -isStream:node,type,intermediate -isString:type,string,beginner -isSymbol:type,beginner -isTravisCI:node,intermediate -isUndefined:type,beginner -isUpperCase:string,utility,beginner -isValidJSON:type,json,intermediate -isWeekday:date,beginner -isWeekend:date,beginner -isWritableStream:node,type,intermediate -join:array,intermediate -JSONtoCSV:array,string,object,advanced -JSONToFile:node,json,intermediate -last:array,beginner -lcm:math,recursion,beginner -longestItem:array,string,utility,intermediate -lowercaseKeys:object,intermediate -luhnCheck:math,utility,advanced -mapKeys:object,function,intermediate -mapNumRange:math,beginner -mapObject:array,object,advanced -mapString:string,array,function,utility,beginner -mapValues:object,function,intermediate -mask:string,utility,regexp,intermediate -matches:object,type,intermediate -matchesWith:object,type,function,intermediate -maxBy:math,array,function,beginner -maxDate:date,math,beginner -maxN:array,math,beginner -median:math,array,intermediate -memoize:function,advanced -merge:object,array,intermediate -midpoint:math,array,beginner -minBy:math,array,function,beginner -minDate:date,math,beginner -minN:array,math,beginner -mostPerformant:utility,function -negate:function,beginner -nest:object,intermediate -nodeListToArray:browser,array,beginner -none:array,function,beginner -nthArg:utility,function,beginner -nthElement:array,beginner -objectFromPairs:object,array,beginner -objectToPairs:object,array,beginner -observeMutations:browser,event,advanced -off:browser,event,intermediate -offset:array,beginner -omit:object,array,intermediate -omitBy:object,array,function,intermediate -on:browser,event,intermediate -once:function,intermediate -onUserInputChange:browser,event,advanced -orderBy:object,array,intermediate -over:adapter,function,intermediate -overArgs:adapter,function,intermediate -pad:string,beginner -palindrome:string,intermediate -parseCookie:utility,string,intermediate -partial:function,intermediate -partialRight:function,intermediate -partition:array,object,function,intermediate -percentile:math,intermediate -permutations:array,recursion,advanced -pick:object,array,intermediate -pickBy:object,array,function,intermediate -pipeAsyncFunctions:adapter,function,promise,intermediate -pipeFunctions:adapter,function,intermediate -pluralize:string,intermediate -powerset:math,beginner -prefix:browser,utility,intermediate -prettyBytes:utility,string,math,advanced -primes:math,array,intermediate -promisify:adapter,function,promise,intermediate -pull:array,intermediate -pullAtIndex:array,advanced -pullAtValue:array,advanced -pullBy:array,function,advanced -radsToDegrees:math,beginner -randomHexColorCode:utility,random,beginner -randomIntArrayInRange:math,utility,random,intermediate -randomIntegerInRange:math,utility,random,beginner -randomNumberInRange:math,utility,random,beginner -readFileLines:node,array,string,beginner -rearg:adapter,function,intermediate -recordAnimationFrames:browser,utility,intermediate -redirect:browser,url,beginner -reducedFilter:array,intermediate -reduceSuccessive:array,function,intermediate -reduceWhich:array,function,intermediate -reject:array,beginner -remove:array,intermediate -removeNonASCII:string,regexp,intermediate -renameKeys:object,intermediate -reverseString:string,array,beginner -RGBToHex:utility,intermediate -round:math,intermediate -runAsync:browser,function,advanced,promise,url -runPromisesInSeries:function,promise,intermediate -sample:array,random,beginner -sampleSize:array,random,intermediate -scrollToTop:browser,intermediate -sdbm:math,utility,intermediate -serializeCookie:utility,string,intermediate -serializeForm:browser,string,intermediate -setStyle:browser,beginner -shallowClone:object,beginner -shank:array,intermediate -show:browser,css,beginner -shuffle:array,random,intermediate -similarity:array,math,beginner -size:object,array,string,intermediate -sleep:function,promise,intermediate -smoothScroll:browser,css,intermediate -sortCharactersInString:string,beginner -sortedIndex:array,math,intermediate -sortedIndexBy:array,math,function,intermediate -sortedLastIndex:array,math,intermediate -sortedLastIndexBy:array,math,function,intermediate -splitLines:string,beginner -spreadOver:adapter,intermediate -stableSort:array,sort,advanced,intermediate -standardDeviation:math,array,intermediate -stringPermutations:string,recursion,advanced -stripHTMLTags:string,utility,regexp,beginner -sum:math,array,beginner -sumBy:math,array,function,intermediate -sumPower:math,intermediate -symmetricDifference:array,math,intermediate -symmetricDifferenceBy:array,function,intermediate -symmetricDifferenceWith:array,function,intermediate -tail:array,beginner -take:array,beginner -takeRight:array,intermediate -takeRightWhile:array,function,intermediate -takeWhile:array,function,intermediate -throttle:function,advanced -times:function,intermediate -timeTaken:utility,beginner -toCamelCase:string,regexp,intermediate -toCurrency:utility,intermediate -toDecimalMark:utility,math,beginner -toggleClass:browser,beginner -toHash:array,intermediate -toKebabCase:string,regexp,intermediate -tomorrow:date,intermediate -toOrdinalSuffix:utility,math,intermediate -toSafeInteger:math,beginner -toSnakeCase:string,regexp,intermediate -toTitleCase:string,regepx,intermediate -transform:object,array,intermediate -triggerEvent:browser,event,intermediate -truncateString:string,beginner -truthCheckCollection:object,logic,array,intermediate -unary:adapter,function,intermediate -uncurry:function,intermediate -unescapeHTML:string,browser,beginner -unflattenObject:object,advanced -unfold:function,array,intermediate -union:array,math,beginner -unionBy:array,function,intermediate -unionWith:array,function,intermediate -uniqueElements:array,beginner -uniqueElementsBy:array,function,intermediate -uniqueElementsByRight:array,function,intermediate -uniqueSymmetricDifference:array,math,intermediate -untildify:node,string,beginner -unzip:array,intermediate -unzipWith:array,function,advanced -URLJoin:string,utility,regexp,advanced -UUIDGeneratorBrowser:browser,utility,random,intermediate -UUIDGeneratorNode:node,utility,random,intermediate -validateNumber:utility,math,intermediate -vectorDistance:math,beginner -when:function,intermediate -without:array,beginner -words:string,regexp,intermediate -xProd:array,math,intermediate -yesNo:utility,regexp,intermediate -yesterday:date,intermediate -zip:array,intermediate -zipObject:array,object,intermediate -zipWith:array,function,advanced