diff --git a/snippets/RGBToHex.md b/snippets/RGBToHex.md index 64e880798..eb13cbeb4 100644 --- a/snippets/RGBToHex.md +++ b/snippets/RGBToHex.md @@ -1,6 +1,6 @@ ### RGBToHex -Converts the values of RGB components to a colorcode. +Converts the values of RGB components to a color code. Convert given RGB parameters to hexadecimal string using bitwise left-shift operator (`<<`) and `toString(16)`, then `padStart(6,'0')` to get a 6-digit hexadecimal value. diff --git a/snippets/arrayLcm.md b/snippets/arrayLcm.md index 5439d5924..3b0ad354c 100644 --- a/snippets/arrayLcm.md +++ b/snippets/arrayLcm.md @@ -1,8 +1,8 @@ ### arrayLcm -Calculates the lowest common multiple (lcm) of an array of numbers. +Calculates the lowest common multiple (lcm) of an array of numbers. -Use `Array.reduce()` and the `lcm` formula (uses recursion) to calculate the lowest common multiple of an array of numbers. +Use `Array.reduce()` and the `lcm` formula (uses recursion) to calculate the lowest common multiple of an array of numbers. ```js const arrayLcm = arr =>{ diff --git a/snippets/clampNumber.md b/snippets/clampNumber.md index ddbb655ff..d1bf9d64f 100644 --- a/snippets/clampNumber.md +++ b/snippets/clampNumber.md @@ -4,7 +4,7 @@ Clamps `num` within the inclusive `lower` and `upper` bounds. If `lower` is greater than `upper`, swap them. If `num` falls within the range, return `num`. -Otherwise return the nearest number in the range. +Otherwise, return the nearest number in the range. ```js const clampNumber = (num, lower, upper) => { diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index 75a8e900b..f2a915719 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -2,7 +2,7 @@ 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 `include`d in given array. +Use `Object.keys()` method to loop over given JSON object and deleting keys that are not `include`d in given array. Also if you give it a special key (`childIndicator`) it will search deeply inside it to apply function to inner objects too. ```js diff --git a/snippets/collatz.md b/snippets/collatz.md index b3d277658..8b8903886 100644 --- a/snippets/collatz.md +++ b/snippets/collatz.md @@ -2,7 +2,7 @@ Applies the Collatz algorithm. -If `n` is even, return `n/2`. Otherwise return `3n+1`. +If `n` is even, return `n/2`. Otherwise, return `3n+1`. ```js const collatz = n => (n % 2 == 0) ? (n / 2) : (3 * n + 1); diff --git a/snippets/countVowels.md b/snippets/countVowels.md index bf1f536fc..c91f09442 100644 --- a/snippets/countVowels.md +++ b/snippets/countVowels.md @@ -2,7 +2,7 @@ Retuns `number` of vowels in provided string. -Use a regular expression to count number of vowels `(A, E, I, O, U)` in a `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]/ig) || []).length; diff --git a/snippets/curry.md b/snippets/curry.md index 50473509e..71d3c12af 100644 --- a/snippets/curry.md +++ b/snippets/curry.md @@ -4,7 +4,7 @@ Curries a function. Use recursion. If the number of provided arguments (`args`) is sufficient, call the passed function `f`. -Otherwise return a curried function `f` that expects the rest of the arguments. +Otherwise, return a curried function `f` that expects the rest of the arguments. If you want to curry a function that accepts a variable number of arguments (a variadic function, e.g. `Math.min()`), you can optionally pass the number of arguments to the second parameter `arity`. ```js diff --git a/snippets/fromCamelCase.md b/snippets/fromCamelCase.md index e004e67ef..3d480dc85 100644 --- a/snippets/fromCamelCase.md +++ b/snippets/fromCamelCase.md @@ -2,7 +2,7 @@ Converts a string from camelcase. -Use `replace()` to remove underscores, hyphens and spaces and convert words to camelcase. +Use `replace()` to remove underscores, hyphens, and spaces and convert words to camelcase. Omit the second argument to use a default separator of `_`. ```js diff --git a/snippets/getDaysDiffBetweenDates.md b/snippets/getDaysDiffBetweenDates.md index d69dea9a3..3b63440c1 100644 --- a/snippets/getDaysDiffBetweenDates.md +++ b/snippets/getDaysDiffBetweenDates.md @@ -2,7 +2,7 @@ Returns the difference (in days) between two dates. -Calculate the difference (in days) between to `Date` objects. +Calculate the difference (in days) between two `Date` objects. ```js const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateInitial) / (1000 * 3600 * 24); diff --git a/snippets/groupBy.md b/snippets/groupBy.md index d5b019498..d83795fdc 100644 --- a/snippets/groupBy.md +++ b/snippets/groupBy.md @@ -1,6 +1,6 @@ ### groupBy -Groups the element of an array based on the given function. +Groups the elements of an array based on the given function. Use `Array.map()` to map the values of an array to a function or property name. Use `Array.reduce()` to create an object, where the keys are produced from the mapped results. diff --git a/snippets/hammingDistance.md b/snippets/hammingDistance.md index bdf3c575b..97c08d2aa 100644 --- a/snippets/hammingDistance.md +++ b/snippets/hammingDistance.md @@ -2,7 +2,7 @@ Calculates the Hamming distance between two values. -Use XOR operator (`^`) to find the bit difference between the two numbers, convert to binary string using `toString(2)`. +Use XOR operator (`^`) to find the bit difference between the two numbers, convert to a binary string using `toString(2)`. Count and return the number of `1`s in the string, using `match(/1/g)`. ```js diff --git a/snippets/hexToRGB.md b/snippets/hexToRGB.md index 2d08b4321..66c95fd3a 100644 --- a/snippets/hexToRGB.md +++ b/snippets/hexToRGB.md @@ -2,7 +2,7 @@ Converts a color code to a `rgb()` or `rgba()` string if alpha value is provided. -Use bitwise right-shift operator and mask bits with `&` (and) operator to convert a hexadecimal color code (with or without prefixed with `#`) to a string with the RGB values. If it's 3-digit color code, first convert to 6-digit version. If any alpha value is provided alongside 6-digit hex, give `rgba()` string in return. +Use bitwise right-shift operator and mask bits with `&` (and) operator to convert a hexadecimal color code (with or without prefixed with `#`) to a string with the RGB values. If it's 3-digit color code, first convert to 6-digit version. If an alpha value is provided alongside 6-digit hex, give `rgba()` string in return. ```js const hexToRGB = hex => { diff --git a/snippets/inRange.md b/snippets/inRange.md index 7162c52d8..5089393dc 100644 --- a/snippets/inRange.md +++ b/snippets/inRange.md @@ -1,9 +1,9 @@ ### inRange -Checks if the given number falls in the given range. +Checks if the given number falls within the given range. Use arithmetic comparison to check if the given number is in the specified range. -If the second parameter, `end`, is not specified, the reange is considered to be from `0` to `start`. +If the second parameter, `end`, is not specified, the range is considered to be from `0` to `start`. ```js const inRange = (n, start, end=null) => { diff --git a/snippets/initial.md b/snippets/initial.md index ad358b593..7b1c5c68c 100644 --- a/snippets/initial.md +++ b/snippets/initial.md @@ -2,7 +2,7 @@ Returns all the elements of an array except the last one. -Use `arr.slice(0,-1)`to return all but the last element of the array. +Use `arr.slice(0,-1)` to return all but the last element of the array. ```js const initial = arr => arr.slice(0, -1); diff --git a/snippets/initialize2DArray.md b/snippets/initialize2DArray.md index cc8b8817b..0cb1df126 100644 --- a/snippets/initialize2DArray.md +++ b/snippets/initialize2DArray.md @@ -1,8 +1,8 @@ ### initialize2DArray -Initializes an 2D array of given width and height and value. +Initializes a 2D array of given width and height and value. -Use `Array.map()` to generate h rows where each is a new array of size w initialize with value. If value is not provided, default to `null`. +Use `Array.map()` to generate h rows where each is a new array of size w initialize with value. If the value is not provided, default to `null`. ```js const initialize2DArray = (w, h, val = null) => Array(h).fill().map(() => Array(w).fill(val)); diff --git a/snippets/isArmstrongNumber.md b/snippets/isArmstrongNumber.md index be8857784..139de9d72 100644 --- a/snippets/isArmstrongNumber.md +++ b/snippets/isArmstrongNumber.md @@ -1,8 +1,8 @@ ### isArmstrongNumber -Checks if the given number is an armstrong number or not. +Checks if the given number is an Armstrong number or not. -Convert the given number into array of digits. Use `Math.pow()` 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`. +Convert the given number into an array of digits. Use `Math.pow()` 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 => diff --git a/snippets/last.md b/snippets/last.md index c72ef4a00..481e2d6e0 100644 --- a/snippets/last.md +++ b/snippets/last.md @@ -2,7 +2,7 @@ Returns the last element in an array. -Use `arr.length - 1` to compute index of the last element of the given array and returning it. +Use `arr.length - 1` to compute the index of the last element of the given array and returning it. ```js const last = arr => arr[arr.length - 1]; diff --git a/snippets/mapObject.md b/snippets/mapObject.md index 102795a73..eb5ea736f 100644 --- a/snippets/mapObject.md +++ b/snippets/mapObject.md @@ -2,7 +2,7 @@ Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the mapped value. -Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new `Array` to stor the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations). +Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new `Array` to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations). ```js const mapObject = (arr, fn) => diff --git a/snippets/pick.md b/snippets/pick.md index b5f5101ea..668c9d30c 100644 --- a/snippets/pick.md +++ b/snippets/pick.md @@ -2,7 +2,7 @@ Picks the key-value pairs corresponding to the given keys from an object. -Use `Array.reduce()` to convert the filtered/picked keys back to a object with the corresponding key-value pair if the key exist in the obj. +Use `Array.reduce()` to convert the filtered/picked keys back to an object with the corresponding key-value pair if the key exists in the obj. ```js const pick = (obj, arr) => diff --git a/snippets/pull.md b/snippets/pull.md index 41658a545..d7d0412c0 100644 --- a/snippets/pull.md +++ b/snippets/pull.md @@ -3,7 +3,7 @@ Mutates the original array to filter out the values specified. Use `Array.filter()` and `Array.includes()` to pull out the values that are not needed. -Use `Array.length = 0` to mutate the passed in array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values. +Use `Array.length = 0` to mutate the passed in an array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values. _(For a snippet that does not mutate the original array see [`without`](#without))_ diff --git a/snippets/pullAtIndex.md b/snippets/pullAtIndex.md index 0e0d8cf7f..260d7b634 100644 --- a/snippets/pullAtIndex.md +++ b/snippets/pullAtIndex.md @@ -3,7 +3,7 @@ Mutates the original array to filter out the values at the specified indexes. Use `Array.filter()` and `Array.includes()` to pull out the values that are not needed. -Use `Array.length = 0` to mutate the passed in array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values. +Use `Array.length = 0` to mutate the passed in an array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values. Use `Array.push()` to keep track of pulled values ```js diff --git a/snippets/pullAtValue.md b/snippets/pullAtValue.md index 64798068f..52e1eac21 100644 --- a/snippets/pullAtValue.md +++ b/snippets/pullAtValue.md @@ -3,7 +3,7 @@ Mutates the original array to filter out the values specified. Returns the removed elements. Use `Array.filter()` and `Array.includes()` to pull out the values that are not needed. -Use `Array.length = 0` to mutate the passed in array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values. +Use `Array.length = 0` to mutate the passed in an array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values. Use `Array.push()` to keep track of pulled values ```js diff --git a/snippets/sample.md b/snippets/sample.md index 241c43167..caf1941e3 100644 --- a/snippets/sample.md +++ b/snippets/sample.md @@ -2,7 +2,7 @@ Returns a random element from an array. -Use `Math.random()` to generate a random number, multiply it with `length` and round it of to the nearest whole number using `Math.floor()`. +Use `Math.random()` to generate a random number, multiply it by `length` and round it of to the nearest whole number using `Math.floor()`. This method also works with strings. ```js diff --git a/snippets/scrollToTop.md b/snippets/scrollToTop.md index dc172f3ee..62cad2588 100644 --- a/snippets/scrollToTop.md +++ b/snippets/scrollToTop.md @@ -3,7 +3,7 @@ Smooth-scrolls to the top of the page. Get distance from top using `document.documentElement.scrollTop` or `document.body.scrollTop`. -Scroll by a fraction of the distance from top. Use `window.requestAnimationFrame()` to animate the scrolling. +Scroll by a fraction of the distance from the top. Use `window.requestAnimationFrame()` to animate the scrolling. ```js const scrollToTop = () => { diff --git a/snippets/select.md b/snippets/select.md index 6f60f4d95..ee243bb8e 100644 --- a/snippets/select.md +++ b/snippets/select.md @@ -1,8 +1,8 @@ ### select -Retrieve a property that indicated by the selector from object. +Retrieve a property that indicated by the selector from an object. -If property not exists returns `undefined`. +If the property does not exists returns `undefined`. ```js const select = (from, selector) => diff --git a/snippets/tail.md b/snippets/tail.md index 781cd2c33..9d84a17f1 100644 --- a/snippets/tail.md +++ b/snippets/tail.md @@ -2,7 +2,7 @@ Returns all elements in an array except for the first one. -Return `arr.slice(1)` if the array's `length` is more than `1`, otherwise return the whole array. +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; diff --git a/snippets/toCamelCase.md b/snippets/toCamelCase.md index 47a984629..20e3821e2 100644 --- a/snippets/toCamelCase.md +++ b/snippets/toCamelCase.md @@ -2,7 +2,7 @@ Converts a string to camelcase. -Use `replace()` to remove underscores, hyphens and spaces and convert words to camelcase. +Use `replace()` to remove underscores, hyphens, and spaces and convert words to camelcase. ```js const toCamelCase = str => diff --git a/snippets/toEnglishDate.md b/snippets/toEnglishDate.md index 5e3038b9d..329eea38b 100644 --- a/snippets/toEnglishDate.md +++ b/snippets/toEnglishDate.md @@ -2,7 +2,7 @@ Converts a date from American format to English format. -Use `Date.toISOString()`, `split('T')` and `replace()` to convert a date from American format to English format. +Use `Date.toISOString()`, `split('T')` and `replace()` to convert a date from American format to the English format. Throws an error if the passed time cannot be converted to a date. ```js diff --git a/snippets/words.md b/snippets/words.md index 38a363a40..df6b258b7 100644 --- a/snippets/words.md +++ b/snippets/words.md @@ -2,7 +2,7 @@ Converts a given string into an array of words. -Use `String.split()` with a supplied pattern (defaults to non alpha as a regex) to convert to an array of strings. Use `Array.filter()` to remove any empty strings. +Use `String.split()` with a supplied pattern (defaults to non-alpha as a regex) to convert to an array of strings. Use `Array.filter()` to remove any empty strings. Omit the second argument to use the default regex. ```js