Fix typos in spaces
Fix typo to fit the context Fix typo add space Fix small typo Fix small typo Fix typo Fix typo Fix typo Fix typo Fix typo Fix typo Fix typo Update tail.md Fix typo Fix small typo Fix typo Fix typo Fix typo Fix typo Fix small typo Fix typo Fix small typo Fix typo Fix typo Fix typo Fix typo Fix typo Fix typo Fix typo Fix typo Fix typo
This commit is contained in:
@ -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.
|
||||
|
||||
|
||||
@ -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 =>{
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 => {
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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 =>
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -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) =>
|
||||
|
||||
@ -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) =>
|
||||
|
||||
@ -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))_
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 = () => {
|
||||
|
||||
@ -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) =>
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 =>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user