Linted everything, removed semistandard
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
},
|
},
|
||||||
"extends": "eslint:recommended",
|
"extends": "eslint:recommended",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2016,
|
"ecmaVersion": 2018,
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
@ -46,7 +46,7 @@
|
|||||||
],
|
],
|
||||||
"brace-style": [
|
"brace-style": [
|
||||||
"error",
|
"error",
|
||||||
"stroustrup",
|
"1tbs",
|
||||||
{
|
{
|
||||||
"allowSingleLine": true
|
"allowSingleLine": true
|
||||||
}
|
}
|
||||||
|
|||||||
156
package-lock.json
generated
156
package-lock.json
generated
@ -3122,12 +3122,6 @@
|
|||||||
"integrity": "sha512-4zaPW5uRFasf2uRZkE19Y+W84KBV3q+oyWYOsgUN+5DQXE5HCsh7ZxeWDXxozk7NPycGm0kXcsJzLe5GZ1jCeg==",
|
"integrity": "sha512-4zaPW5uRFasf2uRZkE19Y+W84KBV3q+oyWYOsgUN+5DQXE5HCsh7ZxeWDXxozk7NPycGm0kXcsJzLe5GZ1jCeg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"eslint-config-standard": {
|
|
||||||
"version": "12.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-12.0.0.tgz",
|
|
||||||
"integrity": "sha512-COUz8FnXhqFitYj4DTqHzidjIL/t4mumGZto5c7DrBpvWoie+Sn3P4sLEzUGeYhRElWuFEf8K1S1EfvD1vixCQ==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"eslint-config-standard-jsx": {
|
"eslint-config-standard-jsx": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-config-standard-jsx/-/eslint-config-standard-jsx-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-config-standard-jsx/-/eslint-config-standard-jsx-5.0.0.tgz",
|
||||||
@ -3185,144 +3179,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"eslint-plugin-es": {
|
"eslint-plugin-async-await": {
|
||||||
"version": "1.3.1",
|
"version": "0.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-1.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-plugin-async-await/-/eslint-plugin-async-await-0.0.0.tgz",
|
||||||
"integrity": "sha512-9XcVyZiQRVeFjqHw8qHNDAZcQLqaHlOGGpeYqzYh8S4JYCWTCO3yzyen8yVmA5PratfzTRWDwCOFphtDEG+w/w==",
|
"integrity": "sha1-DyrhejgUeAY11I8kCd+eN4mMoJ8=",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"eslint-utils": "1.3.1",
|
|
||||||
"regexpp": "2.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"eslint-plugin-import": {
|
|
||||||
"version": "2.14.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.14.0.tgz",
|
|
||||||
"integrity": "sha512-FpuRtniD/AY6sXByma2Wr0TXvXJ4nA/2/04VPlfpmUDPOpOY264x+ILiwnrk/k4RINgDAyFZByxqPUbSQ5YE7g==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"contains-path": "0.1.0",
|
|
||||||
"debug": "2.6.9",
|
|
||||||
"doctrine": "1.5.0",
|
|
||||||
"eslint-import-resolver-node": "0.3.2",
|
|
||||||
"eslint-module-utils": "2.2.0",
|
|
||||||
"has": "1.0.1",
|
|
||||||
"lodash": "4.17.11",
|
|
||||||
"minimatch": "3.0.4",
|
|
||||||
"read-pkg-up": "2.0.0",
|
|
||||||
"resolve": "1.8.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"doctrine": {
|
|
||||||
"version": "1.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
|
|
||||||
"integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"esutils": "2.0.2",
|
|
||||||
"isarray": "1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"find-up": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz",
|
|
||||||
"integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"locate-path": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"path-type": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"pify": "2.3.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"read-pkg": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"load-json-file": "2.0.0",
|
|
||||||
"normalize-package-data": "2.4.0",
|
|
||||||
"path-type": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"read-pkg-up": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"find-up": "2.1.0",
|
|
||||||
"read-pkg": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"resolve": {
|
|
||||||
"version": "1.8.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz",
|
|
||||||
"integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"path-parse": "1.0.5"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"eslint-plugin-node": {
|
|
||||||
"version": "7.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-7.0.1.tgz",
|
|
||||||
"integrity": "sha512-lfVw3TEqThwq0j2Ba/Ckn2ABdwmL5dkOgAux1rvOk6CO7A6yGyPI2+zIxN6FyNkp1X1X/BSvKOceD6mBWSj4Yw==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"eslint-plugin-es": "1.3.1",
|
|
||||||
"eslint-utils": "1.3.1",
|
|
||||||
"ignore": "4.0.6",
|
|
||||||
"minimatch": "3.0.4",
|
|
||||||
"resolve": "1.8.1",
|
|
||||||
"semver": "5.6.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"ignore": {
|
|
||||||
"version": "4.0.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
|
|
||||||
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"resolve": {
|
|
||||||
"version": "1.8.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz",
|
|
||||||
"integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"path-parse": "1.0.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"semver": {
|
|
||||||
"version": "5.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
|
||||||
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"eslint-plugin-promise": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-4.0.1.tgz",
|
|
||||||
"integrity": "sha512-Si16O0+Hqz1gDHsys6RtFRrW7cCTB6P7p3OJmKp3Y3dxpQE2qwOA7d3xnV+0mBmrPoi0RBnxlCKvqu70te6wjg==",
|
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"eslint-plugin-react": {
|
"eslint-plugin-react": {
|
||||||
@ -3337,12 +3197,6 @@
|
|||||||
"prop-types": "15.6.1"
|
"prop-types": "15.6.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"eslint-plugin-standard": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-OwxJkR6TQiYMmt1EsNRMe5qG3GsbjlcOhbGUBY4LtavF9DsLaTcoR+j2Tdjqi23oUwKNUqX7qcn5fPStafMdlA==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"eslint-scope": {
|
"eslint-scope": {
|
||||||
"version": "3.7.1",
|
"version": "3.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
|
||||||
@ -5958,7 +5812,7 @@
|
|||||||
},
|
},
|
||||||
"load-json-file": {
|
"load-json-file": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
||||||
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|||||||
@ -17,8 +17,7 @@
|
|||||||
"prismjs": "^1.15.0",
|
"prismjs": "^1.15.0",
|
||||||
"rollup": "^0.58.2",
|
"rollup": "^0.58.2",
|
||||||
"rollup-plugin-babel": "^4.0.3",
|
"rollup-plugin-babel": "^4.0.3",
|
||||||
"rollup-plugin-babel-minify": "^4.0.0",
|
"rollup-plugin-babel-minify": "^4.0.0"
|
||||||
"semistandard": "^12.0.1"
|
|
||||||
},
|
},
|
||||||
"name": "30-seconds-of-code",
|
"name": "30-seconds-of-code",
|
||||||
"description": "A collection of useful JavaScript snippets.",
|
"description": "A collection of useful JavaScript snippets.",
|
||||||
|
|||||||
@ -52,8 +52,8 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cmd =
|
const cmd =
|
||||||
`semistandard "${TEMP_PATH}" --fix & ` +
|
`prettier "${TEMP_PATH}/*.js" --single-quote --print-width=100 --write & ` +
|
||||||
`prettier "${TEMP_PATH}/*.js" --single-quote --print-width=100 --write`;
|
`eslint "${TEMP_PATH}/*.js" --quiet --fix --rule "no-undef: 0, no-unused-vars: 0, no-multiple-empty-lines: 0" -o eslint_errors.log -f table`;
|
||||||
|
|
||||||
cp.exec(cmd, {}, () => {
|
cp.exec(cmd, {}, () => {
|
||||||
// Loop through each snippet now that semistandard and prettier did their job
|
// Loop through each snippet now that semistandard and prettier did their job
|
||||||
|
|||||||
@ -11,9 +11,9 @@ const call = (key, ...args) => context => context[key](...args);
|
|||||||
```js
|
```js
|
||||||
Promise.resolve([1, 2, 3])
|
Promise.resolve([1, 2, 3])
|
||||||
.then(call('map', x => 2 * x))
|
.then(call('map', x => 2 * x))
|
||||||
.then(console.log); //[ 2, 4, 6 ]
|
.then(console.log); // [ 2, 4, 6 ]
|
||||||
const map = call.bind(null, 'map');
|
const map = call.bind(null, 'map');
|
||||||
Promise.resolve([1, 2, 3])
|
Promise.resolve([1, 2, 3])
|
||||||
.then(map(x => 2 * x))
|
.then(map(x => 2 * x))
|
||||||
.then(console.log); //[ 2, 4, 6 ]
|
.then(console.log); // [ 2, 4, 6 ]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -8,7 +8,7 @@ Calls `Object.freeze(obj)` recursively on all unfrozen properties of passed obje
|
|||||||
const deepFreeze = obj =>
|
const deepFreeze = obj =>
|
||||||
Object.keys(obj).forEach(
|
Object.keys(obj).forEach(
|
||||||
prop =>
|
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);
|
) || Object.freeze(obj);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,6 @@ defer(console.log, 'a'), console.log('b'); // logs 'b' then 'a'
|
|||||||
|
|
||||||
// Example B:
|
// Example B:
|
||||||
document.querySelector('#someElement').innerHTML = 'Hello';
|
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
|
defer(longRunningFunction); // Browser will update the HTML then run the function
|
||||||
```
|
```
|
||||||
|
|||||||
@ -10,9 +10,9 @@ const dig = (obj, target) =>
|
|||||||
target in obj
|
target in obj
|
||||||
? obj[target]
|
? obj[target]
|
||||||
: Object.values(obj).reduce((acc, val) => {
|
: Object.values(obj).reduce((acc, val) => {
|
||||||
if (acc !== undefined) return acc;
|
if (acc !== undefined) return acc;
|
||||||
if (typeof val === 'object') return dig(val, target);
|
if (typeof val === 'object') return dig(val, target);
|
||||||
}, undefined);
|
}, undefined);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -15,9 +15,9 @@ const elo = ([...ratings], kFactor = 32, selfRating) => {
|
|||||||
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||||
const newRating = (rating, i) =>
|
const newRating = (rating, i) =>
|
||||||
(selfRating || rating) + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
(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)];
|
return [newRating(a, 1), newRating(b, 0)];
|
||||||
}
|
|
||||||
for (let i = 0, len = ratings.length; i < len; i++) {
|
for (let i = 0, len = ratings.length; i < len; i++) {
|
||||||
let j = i;
|
let j = i;
|
||||||
while (j < len - 1) {
|
while (j < len - 1) {
|
||||||
|
|||||||
@ -11,8 +11,8 @@ Throws an exception if `n` is a negative number.
|
|||||||
const factorial = n =>
|
const factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
})()
|
})()
|
||||||
: n <= 1
|
: n <= 1
|
||||||
? 1
|
? 1
|
||||||
: n * factorial(n - 1);
|
: n * factorial(n - 1);
|
||||||
|
|||||||
@ -21,7 +21,7 @@ const httpGet = (url, callback, err = console.error) => {
|
|||||||
httpGet(
|
httpGet(
|
||||||
'https://jsonplaceholder.typicode.com/posts/1',
|
'https://jsonplaceholder.typicode.com/posts/1',
|
||||||
console.log
|
console.log
|
||||||
); /*
|
); /*
|
||||||
Logs: {
|
Logs: {
|
||||||
"userId": 1,
|
"userId": 1,
|
||||||
"id": 1,
|
"id": 1,
|
||||||
|
|||||||
@ -42,7 +42,7 @@ Logs: {
|
|||||||
*/
|
*/
|
||||||
httpPost(
|
httpPost(
|
||||||
'https://jsonplaceholder.typicode.com/posts',
|
'https://jsonplaceholder.typicode.com/posts',
|
||||||
null, //does not send a body
|
null, // does not send a body
|
||||||
console.log
|
console.log
|
||||||
); /*
|
); /*
|
||||||
Logs: {
|
Logs: {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ const sum = pipeAsyncFunctions(
|
|||||||
x => x + 3,
|
x => x + 3,
|
||||||
async x => (await x) + 4
|
async x => (await x) + 4
|
||||||
);
|
);
|
||||||
(async () => {
|
(async() => {
|
||||||
console.log(await sum(5)); // 15 (after one second)
|
console.log(await sum(5)); // 15 (after one second)
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|||||||
@ -9,9 +9,9 @@ The `func` is invoked with three arguments (`value, index, array`).
|
|||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
Array.isArray(arr)
|
Array.isArray(arr)
|
||||||
? arr.filter(func).reduce((acc, val) => {
|
? arr.filter(func).reduce((acc, val) => {
|
||||||
arr.splice(arr.indexOf(val), 1);
|
arr.splice(arr.indexOf(val), 1);
|
||||||
return acc.concat(val);
|
return acc.concat(val);
|
||||||
}, [])
|
}, [])
|
||||||
: [];
|
: [];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -29,9 +29,9 @@ const longRunningFunction = () => {
|
|||||||
let result = 0;
|
let result = 0;
|
||||||
for (let i = 0; i < 1000; i++) {
|
for (let i = 0; i < 1000; i++) {
|
||||||
for (let j = 0; j < 700; j++) {
|
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;
|
result = result + i + j + k;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -16,6 +16,6 @@ const sumPower = (end, power = 2, start = 1) =>
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
sumPower(10); // 385
|
sumPower(10); // 385
|
||||||
sumPower(10, 3); //3025
|
sumPower(10, 3); // 3025
|
||||||
sumPower(10, 3, 5); //2925
|
sumPower(10, 3, 5); // 2925
|
||||||
```
|
```
|
||||||
|
|||||||
@ -16,6 +16,6 @@ const unzip = arr =>
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
unzip([['a', 1, true], ['b', 2, false]]); //[['a', 'b'], [1, 2], [true, false]]
|
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]]); // [['a', 'b'], [1, 2], [true]]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
const deepFreeze = obj =>
|
const deepFreeze = obj =>
|
||||||
Object.keys(obj).forEach(
|
Object.keys(obj).forEach(
|
||||||
prop =>
|
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);
|
) || Object.freeze(obj);
|
||||||
module.exports = deepFreeze;
|
module.exports = deepFreeze;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ const dig = (obj, target) =>
|
|||||||
target in obj
|
target in obj
|
||||||
? obj[target]
|
? obj[target]
|
||||||
: Object.values(obj).reduce((acc, val) => {
|
: Object.values(obj).reduce((acc, val) => {
|
||||||
if (acc !== undefined) return acc;
|
if (acc !== undefined) return acc;
|
||||||
if (typeof val === 'object') return dig(val, target);
|
if (typeof val === 'object') return dig(val, target);
|
||||||
}, undefined);
|
}, undefined);
|
||||||
module.exports = dig;
|
module.exports = dig;
|
||||||
|
|||||||
@ -3,9 +3,9 @@ const elo = ([...ratings], kFactor = 32, selfRating) => {
|
|||||||
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||||
const newRating = (rating, i) =>
|
const newRating = (rating, i) =>
|
||||||
(selfRating || rating) + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
(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)];
|
return [newRating(a, 1), newRating(b, 0)];
|
||||||
}
|
|
||||||
for (let i = 0, len = ratings.length; i < len; i++) {
|
for (let i = 0, len = ratings.length; i < len; i++) {
|
||||||
let j = i;
|
let j = i;
|
||||||
while (j < len - 1) {
|
while (j < len - 1) {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
const factorial = n =>
|
const factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
})()
|
})()
|
||||||
: n <= 1
|
: n <= 1
|
||||||
? 1
|
? 1
|
||||||
: n * factorial(n - 1);
|
: n * factorial(n - 1);
|
||||||
|
|||||||
@ -15,4 +15,4 @@ test("getImages returns an Array", () => {
|
|||||||
test("getImages removes duplicates from images Array", () => {
|
test("getImages removes duplicates from images Array", () => {
|
||||||
expect(getImages(TEST_HTML, false).length).toBeLessThanOrEqual(getImages(TEST_HTML, true).length);
|
expect(getImages(TEST_HTML, false).length).toBeLessThanOrEqual(getImages(TEST_HTML, true).length);
|
||||||
expect(getImages(TEST_HTML, true)).toEqual(expect.arrayContaining(getImages(TEST_HTML, false)));
|
expect(getImages(TEST_HTML, true)).toEqual(expect.arrayContaining(getImages(TEST_HTML, false)));
|
||||||
});\n
|
});
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
|
const isPrimitive = val => Object(val) !== val;
|
||||||
module.exports = isPrimitive;
|
module.exports = isPrimitive;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
Array.isArray(arr)
|
Array.isArray(arr)
|
||||||
? arr.filter(func).reduce((acc, val) => {
|
? arr.filter(func).reduce((acc, val) => {
|
||||||
arr.splice(arr.indexOf(val), 1);
|
arr.splice(arr.indexOf(val), 1);
|
||||||
return acc.concat(val);
|
return acc.concat(val);
|
||||||
}, [])
|
}, [])
|
||||||
: [];
|
: [];
|
||||||
module.exports = remove;
|
module.exports = remove;
|
||||||
|
|||||||
2
test/squareSum/squareSum.js
Normal file
2
test/squareSum/squareSum.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
||||||
|
module.exports = squareSum;
|
||||||
6
test/squareSum/squareSum.test.js
Normal file
6
test/squareSum/squareSum.test.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const expect = require('expect');
|
||||||
|
const squareSum = require('./squareSum.js');
|
||||||
|
|
||||||
|
test('squareSum is a Function', () => {
|
||||||
|
expect(squareSum).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
@ -14,7 +14,7 @@ const throttle = (fn, wait) => {
|
|||||||
fn.apply(context, args);
|
fn.apply(context, args);
|
||||||
lastTime = Date.now();
|
lastTime = Date.now();
|
||||||
}
|
}
|
||||||
}, wait - (Date.now() - lastTime));
|
}, Math.max(wait - (Date.now() - lastTime), 0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user