Linted everything, removed semistandard

This commit is contained in:
Angelos Chalaris
2018-10-18 23:38:01 +03:00
parent 1eb609cd90
commit 1fb3e65cca
27 changed files with 55 additions and 194 deletions

View File

@ -11,9 +11,9 @@ const call = (key, ...args) => context => context[key](...args);
```js
Promise.resolve([1, 2, 3])
.then(call('map', x => 2 * x))
.then(console.log); //[ 2, 4, 6 ]
.then(console.log); // [ 2, 4, 6 ]
const map = call.bind(null, 'map');
Promise.resolve([1, 2, 3])
.then(map(x => 2 * x))
.then(console.log); //[ 2, 4, 6 ]
.then(console.log); // [ 2, 4, 6 ]
```

View File

@ -8,7 +8,7 @@ Calls `Object.freeze(obj)` recursively on all unfrozen properties of passed obje
const deepFreeze = obj =>
Object.keys(obj).forEach(
prop =>
!obj[prop] instanceof Object || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
!(obj[prop] instanceof Object) || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
) || Object.freeze(obj);
```

View File

@ -14,6 +14,6 @@ defer(console.log, 'a'), console.log('b'); // logs 'b' then 'a'
// Example B:
document.querySelector('#someElement').innerHTML = 'Hello';
longRunningFunction(); //Browser will not update the HTML until this has finished
longRunningFunction(); // Browser will not update the HTML until this has finished
defer(longRunningFunction); // Browser will update the HTML then run the function
```

View File

@ -10,9 +10,9 @@ const dig = (obj, target) =>
target in obj
? obj[target]
: Object.values(obj).reduce((acc, val) => {
if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target);
}, undefined);
if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target);
}, undefined);
```
```js

View File

@ -15,9 +15,9 @@ const elo = ([...ratings], kFactor = 32, selfRating) => {
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
const newRating = (rating, i) =>
(selfRating || rating) + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
if (ratings.length === 2) {
if (ratings.length === 2)
return [newRating(a, 1), newRating(b, 0)];
}
for (let i = 0, len = ratings.length; i < len; i++) {
let j = i;
while (j < len - 1) {

View File

@ -11,8 +11,8 @@ Throws an exception if `n` is a negative number.
const factorial = n =>
n < 0
? (() => {
throw new TypeError('Negative numbers are not allowed!');
})()
throw new TypeError('Negative numbers are not allowed!');
})()
: n <= 1
? 1
: n * factorial(n - 1);

View File

@ -21,7 +21,7 @@ const httpGet = (url, callback, err = console.error) => {
httpGet(
'https://jsonplaceholder.typicode.com/posts/1',
console.log
); /*
); /*
Logs: {
"userId": 1,
"id": 1,

View File

@ -42,7 +42,7 @@ Logs: {
*/
httpPost(
'https://jsonplaceholder.typicode.com/posts',
null, //does not send a body
null, // does not send a body
console.log
); /*
Logs: {

View File

@ -17,7 +17,7 @@ const sum = pipeAsyncFunctions(
x => x + 3,
async x => (await x) + 4
);
(async () => {
(async() => {
console.log(await sum(5)); // 15 (after one second)
})();
```

View File

@ -9,9 +9,9 @@ The `func` is invoked with three arguments (`value, index, array`).
const remove = (arr, func) =>
Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
: [];
```

View File

@ -29,9 +29,9 @@ const longRunningFunction = () => {
let result = 0;
for (let i = 0; i < 1000; i++) {
for (let j = 0; j < 700; j++) {
for (let k = 0; k < 300; k++) {
for (let k = 0; k < 300; k++)
result = result + i + j + k;
}
}
}
return result;

View File

@ -16,6 +16,6 @@ const sumPower = (end, power = 2, start = 1) =>
```js
sumPower(10); // 385
sumPower(10, 3); //3025
sumPower(10, 3, 5); //2925
sumPower(10, 3); // 3025
sumPower(10, 3, 5); // 2925
```

View File

@ -16,6 +16,6 @@ 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]]
unzip([['a', 1, true], ['b', 2, false]]); // [['a', 'b'], [1, 2], [true, false]]
unzip([['a', 1, true], ['b', 2]]); // [['a', 'b'], [1, 2], [true]]
```