Consistent whitespace

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-11-03 21:46:13 +02:00
parent f057d4d95b
commit 81e37d20c0
11 changed files with 16 additions and 13 deletions

View File

@ -19,7 +19,7 @@ const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
```
```js
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']];
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']];
```

View File

@ -6,7 +6,7 @@ tags: string,math,intermediate
Converts the values of RGB components to a hexadecimal color code.
- Convert given RGB parameters to hexadecimal string using bitwise left-shift operator (`<<`) and `Number.prototype.toString(16)`.
- Use `String.prototype.padStart(6,'0')` to get a 6-digit hexadecimal value.
- Use `String.prototype.padStart(6, '0')` to get a 6-digit hexadecimal value.
```js
const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6, '0');

View File

@ -10,7 +10,7 @@ Creates an array of partial sums.
```js
const accumulate = (...nums) =>
nums.reduce((acc, n) => [...acc, n + +acc.slice(-1)],[]);
nums.reduce((acc, n) => [...acc, n + +acc.slice(-1)], []);
```
```js

View File

@ -20,5 +20,5 @@ const chunkIntoN = (arr, n) => {
```
```js
chunkIntoN([1, 2, 3, 4, 5, 6, 7], 4); // [[1,2], [3,4], [5,6], [7]]
chunkIntoN([1, 2, 3, 4, 5, 6, 7], 4); // [[1, 2], [3, 4], [5, 6], [7]]
```

View File

@ -5,7 +5,7 @@ tags: array,beginner
Returns all the elements of an array except the last one.
- Use `Array.prototype.slice(0,-1)` to return all but the last element of the array.
- Use `Array.prototype.slice(0, -1)` to return all but the last element of the array.
```js
const initial = arr => arr.slice(0, -1);

View File

@ -5,7 +5,7 @@ tags: math,recursion,intermediate
Calculates the least common multiple of two or more numbers.
- Use the greatest common divisor (GCD) formula and the fact that `lcm(x,y) = x * y / gcd(x,y)` to determine the least common multiple.
- Use the greatest common divisor (GCD) formula and the fact that `lcm(x, y) = x * y / gcd(x, y)` to determine the least common multiple.
- The GCD formula uses recursion.
```js

View File

@ -6,7 +6,7 @@ tags: math,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.
- Use `String.prototype.split('')`, `Array.prototype.reverse()` and `Array.prototype.map()` in combination with `parseInt()` to obtain an array of digits.
- Use `Array.prototype.splice(0,1)` to obtain the last digit.
- 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.

View File

@ -25,5 +25,8 @@ const users = [
{ user: 'fred', age: 40, active: true },
];
partition(users, o => o.active);
// [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]
// [
// [{ user: 'fred', age: 40, active: true }],
// [{ user: 'barney', age: 36, active: false }]
// ]
```

View File

@ -8,7 +8,7 @@ Returns a string with whitespaces removed.
- Use `String.prototype.replace()` with a regular expression to replace all occurrences of whitespace characters with an empty string.
```js
const removeWhitespace = str => str.replace(/\s+/g,'');
const removeWhitespace = str => str.replace(/\s+/g, '');
```
```js

View File

@ -23,5 +23,5 @@ const weightedAverage = (nums, weights) => {
```
```js
weightedAverage([1, 2, 3], [0.6,0.2,0.3]); // 1.72727
weightedAverage([1, 2, 3], [0.6, 0.2, 0.3]); // 1.72727
```

View File

@ -22,7 +22,7 @@ const zipWith = (...array) => {
```
```js
zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c); // [111,222]
zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c); // [111, 222]
zipWith(
[1, 2, 3],
[10, 20],