diff --git a/snippets/UUID-generator.md b/snippets/UUID-generator.md index 342fce12b..90dd9c78a 100644 --- a/snippets/UUID-generator.md +++ b/snippets/UUID-generator.md @@ -3,7 +3,7 @@ Use `crypto` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4. ```js -const uuid = () => +const uuidGenerator = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); diff --git a/snippets/anagrams-of-string-(with-duplicates).md b/snippets/anagrams.md similarity index 100% rename from snippets/anagrams-of-string-(with-duplicates).md rename to snippets/anagrams.md diff --git a/snippets/average-of-array-of-numbers.md b/snippets/average.md similarity index 100% rename from snippets/average-of-array-of-numbers.md rename to snippets/average.md diff --git a/snippets/capitalize-first-letter-of-every-word.md b/snippets/capitalize-every-word.md similarity index 100% rename from snippets/capitalize-first-letter-of-every-word.md rename to snippets/capitalize-every-word.md diff --git a/snippets/capitalize-first-letter.md b/snippets/capitalize.md similarity index 100% rename from snippets/capitalize-first-letter.md rename to snippets/capitalize.md diff --git a/snippets/chain-asynchronous-functions.md b/snippets/chain-async.md similarity index 100% rename from snippets/chain-asynchronous-functions.md rename to snippets/chain-async.md diff --git a/snippets/chunk-array.md b/snippets/chunk.md similarity index 100% rename from snippets/chunk-array.md rename to snippets/chunk.md diff --git a/snippets/clean-JSON-object.md b/snippets/clean-obj.md similarity index 100% rename from snippets/clean-JSON-object.md rename to snippets/clean-obj.md diff --git a/snippets/collatz-algorithm.md b/snippets/collatz.md similarity index 100% rename from snippets/collatz-algorithm.md rename to snippets/collatz.md diff --git a/snippets/compose-functions.md b/snippets/compose.md similarity index 100% rename from snippets/compose-functions.md rename to snippets/compose.md diff --git a/snippets/count-occurrences-of-a-value-in-array.md b/snippets/count-occurrences.md similarity index 100% rename from snippets/count-occurrences-of-a-value-in-array.md rename to snippets/count-occurrences.md diff --git a/snippets/deep-flatten-array.md b/snippets/deep-flatten.md similarity index 100% rename from snippets/deep-flatten-array.md rename to snippets/deep-flatten.md diff --git a/snippets/array-difference.md b/snippets/difference.md similarity index 100% rename from snippets/array-difference.md rename to snippets/difference.md diff --git a/snippets/number-to-array-of-digits.md b/snippets/digitalize.md similarity index 100% rename from snippets/number-to-array-of-digits.md rename to snippets/digitalize.md diff --git a/snippets/distance-between-two-points.md b/snippets/distance.md similarity index 100% rename from snippets/distance-between-two-points.md rename to snippets/distance.md diff --git a/snippets/drop-elements-in-array.md b/snippets/drop-elements.md similarity index 100% rename from snippets/drop-elements-in-array.md rename to snippets/drop-elements.md diff --git a/snippets/escape-regular-expression.md b/snippets/escape-reg-exp.md similarity index 100% rename from snippets/escape-regular-expression.md rename to snippets/escape-reg-exp.md diff --git a/snippets/take-every-nth-element.md b/snippets/every-nth.md similarity index 73% rename from snippets/take-every-nth-element.md rename to snippets/every-nth.md index 8db496353..8fa385b7c 100644 --- a/snippets/take-every-nth-element.md +++ b/snippets/every-nth.md @@ -3,6 +3,6 @@ Use `Array.filter()` to create a new array that contains every nth element of a given array. ```js -const everynth = (arr, nth) => arr.filter((e, i) => i % nth === 0); +const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === 0); // everynth([1,2,3,4,5,6], 2) -> [ 1, 3, 5 ] ``` diff --git a/snippets/3-digit-hexcode-to-6-digit-hexcode.md b/snippets/extend-hex.md similarity index 93% rename from snippets/3-digit-hexcode-to-6-digit-hexcode.md rename to snippets/extend-hex.md index 3c1c87261..21f882963 100644 --- a/snippets/3-digit-hexcode-to-6-digit-hexcode.md +++ b/snippets/extend-hex.md @@ -3,7 +3,7 @@ Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for converting a three-digit RGB notated hexadecimal color-code to the six-digit form. `Array.slice()` is used to remove `#` from string start since it's added once. ```js -const convertHex = shortHex => +const extendHex = shortHex => '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split().map(x => x+x).join() // convertHex('#03f') -> '#0033ff' // convertHex('05a') -> '#0055aa' diff --git a/snippets/fibonacci-array-generator.md b/snippets/fibonacci.md similarity index 100% rename from snippets/fibonacci-array-generator.md rename to snippets/fibonacci.md diff --git a/snippets/filter-out-non-unique-values-in-an-array.md b/snippets/filter-non-unique.md similarity index 100% rename from snippets/filter-out-non-unique-values-in-an-array.md rename to snippets/filter-non-unique.md diff --git a/snippets/flatten-array-up-to-depth.md b/snippets/flatten-depth.md similarity index 100% rename from snippets/flatten-array-up-to-depth.md rename to snippets/flatten-depth.md diff --git a/snippets/flatten-array.md b/snippets/flatten.md similarity index 100% rename from snippets/flatten-array.md rename to snippets/flatten.md diff --git a/snippets/convert-string-from-camelcase.md b/snippets/from-camel-case.md similarity index 100% rename from snippets/convert-string-from-camelcase.md rename to snippets/from-camel-case.md diff --git a/snippets/log-function-name.md b/snippets/function-name.md similarity index 100% rename from snippets/log-function-name.md rename to snippets/function-name.md diff --git a/snippets/get-days-difference-between-dates.md b/snippets/get-days-diff-between-dates.md similarity index 100% rename from snippets/get-days-difference-between-dates.md rename to snippets/get-days-diff-between-dates.md diff --git a/snippets/get-max-value-from-array.md b/snippets/get-max.md similarity index 100% rename from snippets/get-max-value-from-array.md rename to snippets/get-max.md diff --git a/snippets/get-min-value-from-array.md b/snippets/get-min.md similarity index 100% rename from snippets/get-min-value-from-array.md rename to snippets/get-min.md diff --git a/snippets/get-scroll-position.md b/snippets/get-scroll-position.md index 4f134a9fb..0f99bc757 100644 --- a/snippets/get-scroll-position.md +++ b/snippets/get-scroll-position.md @@ -4,7 +4,7 @@ Use `pageXOffset` and `pageYOffset` if they are defined, otherwise `scrollLeft` You can omit `el` to use a default value of `window`. ```js -const getScrollPos = (el = window) => +const getScrollPosition = (el = window) => ({x: (el.pageXOffset !== undefined) ? el.pageXOffset : el.scrollLeft, y: (el.pageYOffset !== undefined) ? el.pageYOffset : el.scrollTop}); // getScrollPos() -> {x: 0, y: 200} diff --git a/snippets/get-native-type-of-value.md b/snippets/get-type.md similarity index 100% rename from snippets/get-native-type-of-value.md rename to snippets/get-type.md diff --git a/snippets/URL-parameters.md b/snippets/get-url-parameters.md similarity index 100% rename from snippets/URL-parameters.md rename to snippets/get-url-parameters.md diff --git a/snippets/greatest-common-divisor-(GCD).md b/snippets/greatest-common-divisor.md similarity index 77% rename from snippets/greatest-common-divisor-(GCD).md rename to snippets/greatest-common-divisor.md index d1025a029..d4b2688ed 100644 --- a/snippets/greatest-common-divisor-(GCD).md +++ b/snippets/greatest-common-divisor.md @@ -5,6 +5,6 @@ Base case is when `y` equals `0`. In this case, return `x`. Otherwise, return the GCD of `y` and the remainder of the division `x/y`. ```js -const gcd = (x, y) => !y ? x : gcd(y, x % y); +const greatestCommonDivisor = (x, y) => !y ? x : gcd(y, x % y); // gcd (8, 36) -> 4 ``` diff --git a/snippets/head-of-list.md b/snippets/head.md similarity index 100% rename from snippets/head-of-list.md rename to snippets/head.md diff --git a/snippets/hexcode-to-RGB.md b/snippets/hex-to-rgb.md similarity index 100% rename from snippets/hexcode-to-RGB.md rename to snippets/hex-to-rgb.md diff --git a/snippets/initial-of-list.md b/snippets/initial.md similarity index 100% rename from snippets/initial-of-list.md rename to snippets/initial.md diff --git a/snippets/initialize-array-with-range.md b/snippets/initialize-array-range.md similarity index 100% rename from snippets/initialize-array-with-range.md rename to snippets/initialize-array-range.md diff --git a/snippets/initialize-array-with-values.md b/snippets/initialize-array.md similarity index 100% rename from snippets/initialize-array-with-values.md rename to snippets/initialize-array.md diff --git a/snippets/array-intersection.md b/snippets/intersection.md similarity index 100% rename from snippets/array-intersection.md rename to snippets/intersection.md diff --git a/snippets/divisible-by-number.md b/snippets/is-divisible.md similarity index 100% rename from snippets/divisible-by-number.md rename to snippets/is-divisible.md diff --git a/snippets/even-or-odd-number.md b/snippets/is-even.md similarity index 100% rename from snippets/even-or-odd-number.md rename to snippets/is-even.md diff --git a/snippets/write-json-to-file.md b/snippets/json-to-file.md similarity index 100% rename from snippets/write-json-to-file.md rename to snippets/json-to-file.md diff --git a/snippets/last-of-list.md b/snippets/last-of-list.md index b4729b152..103c5872b 100644 --- a/snippets/last-of-list.md +++ b/snippets/last-of-list.md @@ -3,6 +3,6 @@ Use `arr.length - 1` to compute index of the last element of the given array and returning it. ```js -const last = arr => arr[arr.length - 1]; +const lastOfArray = arr => arr[arr.length - 1]; // last([1,2,3]) -> 3 ``` diff --git a/snippets/least-common-multiple-(LCM).md b/snippets/least-common-multiple-(LCM).md index 4f3fc2822..f44dd59b0 100644 --- a/snippets/least-common-multiple-(LCM).md +++ b/snippets/least-common-multiple-(LCM).md @@ -4,7 +4,7 @@ Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the The GCD formula uses recursion. ```js -const lcm = (x,y) => { +const leastCommonMultiple = (x,y) => { const gcd = (x, y) => !y ? x : gcd(y, x % y); return Math.abs(x*y)/(gcd(x,y)); }; diff --git a/snippets/median-of-array-of-numbers.md b/snippets/median-array.md similarity index 100% rename from snippets/median-of-array-of-numbers.md rename to snippets/median-array.md diff --git a/snippets/nth-element-of-array.md b/snippets/nth-element.md similarity index 74% rename from snippets/nth-element-of-array.md rename to snippets/nth-element.md index 15552d071..bb3d131f5 100644 --- a/snippets/nth-element-of-array.md +++ b/snippets/nth-element.md @@ -1,11 +1,11 @@ ### Nth element of array -Use `Array.slice()` to get an array containing the nth element at the first place. +Use `Array.slice()` to get an array containing the nth element at the first place. If the index is out of bounds, return `[]`. Omit the second argument, `n`, to get the first element of the array. ```js -const nth = (arr, n=0) => (n>0? arr.slice(n,n+1) : arr.slice(n))[0]; +const nthElement = (arr, n=0) => (n>0? arr.slice(n,n+1) : arr.slice(n))[0]; // nth(['a','b','c'],1) -> 'b' // nth(['a','b','b']-2) -> 'a' ``` diff --git a/snippets/object-from-key-value-pairs.md b/snippets/object-from-pairs.md similarity index 100% rename from snippets/object-from-key-value-pairs.md rename to snippets/object-from-pairs.md diff --git a/snippets/object-to-key-value-pairs.md b/snippets/object-to-pairs.md similarity index 100% rename from snippets/object-to-key-value-pairs.md rename to snippets/object-to-pairs.md diff --git a/snippets/check-for-palindrome.md b/snippets/palindrome.md similarity index 100% rename from snippets/check-for-palindrome.md rename to snippets/palindrome.md diff --git a/snippets/pipe-functions.md b/snippets/pipe-functions.md index 6e34e1063..8ec3b1bd1 100644 --- a/snippets/pipe-functions.md +++ b/snippets/pipe-functions.md @@ -4,7 +4,7 @@ Use `Array.reduce()` with the spread operator (`...`) to perform left-to-right f The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. ```js -const pipe = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); +const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); /* const add5 = x => x + 5 const multiply = (x, y) => x * y diff --git a/snippets/array-pull-(mutates-array).md b/snippets/pull.md similarity index 100% rename from snippets/array-pull-(mutates-array).md rename to snippets/pull.md diff --git a/snippets/random-number-in-range.md b/snippets/random-number-in-range.md index f2592b78e..2ff50d332 100644 --- a/snippets/random-number-in-range.md +++ b/snippets/random-number-in-range.md @@ -3,6 +3,6 @@ Use `Math.random()` to generate a random value, map it to the desired range using multiplication. ```js -const randomInRange = (min, max) => Math.random() * (max - min) + min; +const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; // randomInRange(2,10) -> 6.0211363285087005 ``` diff --git a/snippets/read-file-as-array-of-lines.md b/snippets/read-file-to-array.md similarity index 100% rename from snippets/read-file-as-array-of-lines.md rename to snippets/read-file-to-array.md diff --git a/snippets/array-remove.md b/snippets/remove.md similarity index 100% rename from snippets/array-remove.md rename to snippets/remove.md diff --git a/snippets/reverse-a-string.md b/snippets/reverse-string.md similarity index 100% rename from snippets/reverse-a-string.md rename to snippets/reverse-string.md diff --git a/snippets/round-number-to-n-digits.md b/snippets/round-number.md similarity index 100% rename from snippets/round-number-to-n-digits.md rename to snippets/round-number.md diff --git a/snippets/run-promises-in-series.md b/snippets/run-promises-in-series.md index 2193e8df4..c078dff8d 100644 --- a/snippets/run-promises-in-series.md +++ b/snippets/run-promises-in-series.md @@ -3,7 +3,7 @@ Run an array of promises in series using `Array.reduce()` by creating a promise chain, where each promise returns the next promise when resolved. ```js -const series = ps => ps.reduce((p, next) => p.then(next), Promise.resolve()); +const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve()); // const delay = (d) => new Promise(r => setTimeout(r, d)) // series([() => delay(1000), () => delay(2000)]) -> executes each promise sequentially, taking a total of 3 seconds to complete ``` diff --git a/snippets/array-sample.md b/snippets/sample.md similarity index 100% rename from snippets/array-sample.md rename to snippets/sample.md diff --git a/snippets/shallow-clone-object.md b/snippets/shallow-clone.md similarity index 100% rename from snippets/shallow-clone-object.md rename to snippets/shallow-clone.md diff --git a/snippets/shuffle-array.md b/snippets/shuffle-array.md index 6266f9ecf..85065b40a 100644 --- a/snippets/shuffle-array.md +++ b/snippets/shuffle-array.md @@ -3,6 +3,6 @@ Use `Array.sort()` to reorder elements, using `Math.random()` in the comparator. ```js -const shuffle = arr => arr.sort(() => Math.random() - 0.5); +const shuffleArray = arr => arr.sort(() => Math.random() - 0.5); // shuffle([1,2,3]) -> [2,3,1] ``` diff --git a/snippets/similarity-between-arrays.md b/snippets/similarity.md similarity index 100% rename from snippets/similarity-between-arrays.md rename to snippets/similarity.md diff --git a/snippets/speech-synthesis-(experimental).md b/snippets/speech-synthesis-(experimental).md index 2a5cb1d20..2bfbc9c75 100644 --- a/snippets/speech-synthesis-(experimental).md +++ b/snippets/speech-synthesis-(experimental).md @@ -6,7 +6,7 @@ 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 speak = message => { +const speechSynthesis = message => { const msg = new SpeechSynthesisUtterance(message); msg.voice = window.speechSynthesis.getVoices()[0]; window.speechSynthesis.speak(msg); diff --git a/snippets/sum-of-array-of-numbers.md b/snippets/sum-array-numbers.md similarity index 68% rename from snippets/sum-of-array-of-numbers.md rename to snippets/sum-array-numbers.md index 9729eb474..a6187b3dc 100644 --- a/snippets/sum-of-array-of-numbers.md +++ b/snippets/sum-array-numbers.md @@ -3,6 +3,6 @@ Use `Array.reduce()` to add each value to an accumulator, initialized with a value of `0`. ```js -const sum = arr => arr.reduce((acc, val) => acc + val, 0); +const sumArrayNumbers = arr => arr.reduce((acc, val) => acc + val, 0); // sum([1,2,3,4]) -> 10 ``` diff --git a/snippets/array-symmetric-difference.md b/snippets/symmetric-difference.md similarity index 100% rename from snippets/array-symmetric-difference.md rename to snippets/symmetric-difference.md diff --git a/snippets/tail-of-list.md b/snippets/tail-of-list.md index d0c9681c3..f41e63982 100644 --- a/snippets/tail-of-list.md +++ b/snippets/tail-of-list.md @@ -3,7 +3,7 @@ Return `arr.slice(1)` if the array's `length` is more than `1`, otherwise return the whole array. ```js -const tail = arr => arr.length > 1 ? arr.slice(1) : arr; +const tailOfList = arr => arr.length > 1 ? arr.slice(1) : arr; // tail([1,2,3]) -> [2,3] // tail([1]) -> [1] ``` diff --git a/snippets/measure-time-taken-by-function.md b/snippets/time-taken.md similarity index 100% rename from snippets/measure-time-taken-by-function.md rename to snippets/time-taken.md diff --git a/snippets/convert-string-to-camelcase.md b/snippets/to-camel-case.md similarity index 100% rename from snippets/convert-string-to-camelcase.md rename to snippets/to-camel-case.md diff --git a/snippets/convert-to-english-date.md b/snippets/to-english-date.md similarity index 100% rename from snippets/convert-to-english-date.md rename to snippets/to-english-date.md diff --git a/snippets/ordinal-suffix-of-number.md b/snippets/to-ordinal-suffix.md similarity index 100% rename from snippets/ordinal-suffix-of-number.md rename to snippets/to-ordinal-suffix.md diff --git a/snippets/truncate-a-string.md b/snippets/truncate-string.md similarity index 89% rename from snippets/truncate-a-string.md rename to snippets/truncate-string.md index a33ac6367..4fb103895 100644 --- a/snippets/truncate-a-string.md +++ b/snippets/truncate-string.md @@ -4,7 +4,7 @@ Determine if the string's `length` is greater than `num`. Return the string truncated to the desired length, with `...` appended to the end or the original string. ```js -const truncate = (str, num) => +const truncateString = (str, num) => str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str; // truncate('boomerang', 7) -> 'boom...' ``` diff --git a/snippets/array-union.md b/snippets/union.md similarity index 100% rename from snippets/array-union.md rename to snippets/union.md diff --git a/snippets/unique-values-of-array.md b/snippets/unique-values-of-array.md index 0d7639815..0383731bc 100644 --- a/snippets/unique-values-of-array.md +++ b/snippets/unique-values-of-array.md @@ -3,6 +3,6 @@ Use ES6 `Set` and the `...rest` operator to discard all duplicated values. ```js -const unique = arr => [...new Set(arr)]; +const uniqueValuesOfArray = arr => [...new Set(arr)]; // unique([1,2,2,3,4,4,5]) -> [1,2,3,4,5] ``` diff --git a/snippets/array-without.md b/snippets/without.md similarity index 100% rename from snippets/array-without.md rename to snippets/without.md diff --git a/snippets/array-zip.md b/snippets/zip.md similarity index 100% rename from snippets/array-zip.md rename to snippets/zip.md