Travis build: 527 [cron]
This commit is contained in:
@ -297,8 +297,8 @@
|
|||||||
"fibonacciCountUntilNum(10); // 7",
|
"fibonacciCountUntilNum(10); // 7",
|
||||||
"const fibonacciUntilNum = num => {\n let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));\n return Array.from({ length: n }).reduce(\n (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),\n []\n );\n};",
|
"const fibonacciUntilNum = num => {\n let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));\n return Array.from({ length: n }).reduce(\n (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),\n []\n );\n};",
|
||||||
"fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]",
|
"fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]",
|
||||||
"const httpDelete = (url, callback, err = console.error) => {\n const request = new XMLHttpRequest();\n request.open('DELETE', url, true);\n request.onload = () => callback(request);\n request.onerror = () => err(request);\n request.send();\n};",
|
"const howManyTimes = (num, divisor) => {\n if (divisor === 1 || divisor === -1) return Infinity;\n if (divisor === 0) return 0;\n let i = 0;\n while (Number.isInteger(num / divisor)) {\n i++;\n num = num / divisor;\n }\n return i;\n};",
|
||||||
"httpDelete('https://website.com/users/123', request => {\n console.log(request.responseText);\n}); // 'Deletes a user from the database'",
|
"howManyTimes(100, 2); // 2\nhowManyTimes(100, 2.5); // 2\nhowManyTimes(100, 0); // 0\nhowManyTimes(100, -1); // Infinity",
|
||||||
"const httpPut = (url, data, callback, err = console.error) => {\n const request = new XMLHttpRequest();\n request.open(\"PUT\", url, true);\n request.setRequestHeader('Content-type','application/json; charset=utf-8');\n request.onload = () => callback(request);\n request.onerror = () => err(request);\n request.send(data);\n};",
|
"const httpPut = (url, data, callback, err = console.error) => {\n const request = new XMLHttpRequest();\n request.open(\"PUT\", url, true);\n request.setRequestHeader('Content-type','application/json; charset=utf-8');\n request.onload = () => callback(request);\n request.onerror = () => err(request);\n request.send(data);\n};",
|
||||||
"const password = \"fooBaz\";\nconst data = JSON.stringify(password);\nhttpPut('https://website.com/users/123', data, request => {\n console.log(request.responseText);\n}); // 'Updates a user's password in database'",
|
"const password = \"fooBaz\";\nconst data = JSON.stringify(password);\nhttpPut('https://website.com/users/123', data, request => {\n console.log(request.responseText);\n}); // 'Updates a user's password in database'",
|
||||||
"const isArmstrongNumber = digits =>\n (arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(\n (digits + '').split('')\n );",
|
"const isArmstrongNumber = digits =>\n (arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(\n (digits + '').split('')\n );",
|
||||||
@ -307,20 +307,22 @@
|
|||||||
"isSimilar('rt','Rohit'); // true\nisSimilar('tr','Rohit'); // false",
|
"isSimilar('rt','Rohit'); // true\nisSimilar('tr','Rohit'); // false",
|
||||||
"``` js\nconst levenshteinDistance = (string1, string2) => {\n if (string1.length === 0) return string2.length;\n if (string2.length === 0) return string1.length;\n let matrix = Array(string2.length + 1)\n .fill(0)\n .map((x, i) => [i]);\n matrix[0] = Array(string1.length + 1)\n .fill(0)\n .map((x, i) => i);\n for (let i = 1; i <= string2.length; i++) {\n for (let j = 1; j <= string1.length; j++) {\n if (string2[i - 1] === string1[j - 1]) {\n matrix[i][j] = matrix[i - 1][j - 1];\n } else {\n matrix[i][j] = Math.min(\n matrix[i - 1][j - 1] + 1,\n matrix[i][j - 1] + 1,\n matrix[i - 1][j] + 1\n );\n }\n }\n }\n return matrix[string2.length][string1.length];\n};\n```",
|
"``` js\nconst levenshteinDistance = (string1, string2) => {\n if (string1.length === 0) return string2.length;\n if (string2.length === 0) return string1.length;\n let matrix = Array(string2.length + 1)\n .fill(0)\n .map((x, i) => [i]);\n matrix[0] = Array(string1.length + 1)\n .fill(0)\n .map((x, i) => i);\n for (let i = 1; i <= string2.length; i++) {\n for (let j = 1; j <= string1.length; j++) {\n if (string2[i - 1] === string1[j - 1]) {\n matrix[i][j] = matrix[i - 1][j - 1];\n } else {\n matrix[i][j] = Math.min(\n matrix[i - 1][j - 1] + 1,\n matrix[i][j - 1] + 1,\n matrix[i - 1][j] + 1\n );\n }\n }\n }\n return matrix[string2.length][string1.length];\n};\n```",
|
||||||
"levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7\nconst compareStrings = (string1,string2) => (100 - levenshteinDistance(string1,string2) / Math.max(string1.length,string2.length));\ncompareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)",
|
"levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7\nconst compareStrings = (string1,string2) => (100 - levenshteinDistance(string1,string2) / Math.max(string1.length,string2.length));\ncompareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)",
|
||||||
|
"const pipeLog = data => console.log(data) || data;",
|
||||||
|
"pipeLog(1); // logs `1` and returns `1`",
|
||||||
"const quickSort = ([n, ...nums], desc) =>\n isNaN(n)\n ? []\n : [\n ...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),\n n,\n ...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)\n ];",
|
"const quickSort = ([n, ...nums], desc) =>\n isNaN(n)\n ? []\n : [\n ...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),\n n,\n ...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)\n ];",
|
||||||
"quickSort([4, 1, 3, 2]); // [1,2,3,4]\nquickSort([4, 1, 3, 2], true); // [4,3,2,1]",
|
"quickSort([4, 1, 3, 2]); // [1,2,3,4]\nquickSort([4, 1, 3, 2], true); // [4,3,2,1]",
|
||||||
"const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);",
|
"const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);",
|
||||||
"removeVowels(\"foobAr\"); // \"fbr\"\nremoveVowels(\"foobAr\",\"*\"); // \"f**b*r\"",
|
"removeVowels(\"foobAr\"); // \"fbr\"\nremoveVowels(\"foobAr\",\"*\"); // \"f**b*r\"",
|
||||||
"const solveRPN = rpn => {\n const OPERATORS = {\n '*': (a, b) => a * b,\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '/': (a, b) => a / b,\n '**': (a, b) => a ** b\n };\n const [stack, solve] = [\n [],\n rpn\n .replace(/\\^/g, '**')\n .split(/\\s+/g)\n .filter(el => !/\\s+/.test(el) && el !== '')\n ];\n solve.forEach(symbol => {\n if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {\n stack.push(symbol);\n } else if (Object.keys(OPERATORS).includes(symbol)) {\n const [a, b] = [stack.pop(), stack.pop()];\n stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));\n } else {\n throw `${symbol} is not a recognized symbol`;\n }\n });\n if (stack.length === 1) return stack.pop();\n else throw `${rpn} is not a proper RPN. Please check it and try again`;\n};",
|
"const solveRPN = rpn => {\n const OPERATORS = {\n '*': (a, b) => a * b,\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '/': (a, b) => a / b,\n '**': (a, b) => a ** b\n };\n const [stack, solve] = [\n [],\n rpn\n .replace(/\\^/g, '**')\n .split(/\\s+/g)\n .filter(el => !/\\s+/.test(el) && el !== '')\n ];\n solve.forEach(symbol => {\n if (!isNaN(parseFloat(symbol)) && isFinite(symbol)) {\n stack.push(symbol);\n } else if (Object.keys(OPERATORS).includes(symbol)) {\n const [a, b] = [stack.pop(), stack.pop()];\n stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));\n } else {\n throw `${symbol} is not a recognized symbol`;\n }\n });\n if (stack.length === 1) return stack.pop();\n else throw `${rpn} is not a proper RPN. Please check it and try again`;\n};",
|
||||||
"solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5\nsolveRPN('2 3 ^'); // 8",
|
"solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5\nsolveRPN('2 3 ^'); // 8",
|
||||||
"const howManyTimes = (num, divisor) => {\n if (divisor === 1 || divisor === -1) return Infinity;\n if (divisor === 0) return 0;\n let i = 0;\n while (Number.isInteger(num / divisor)) {\n i++;\n num = num / divisor;\n }\n return i;\n};",
|
"const httpDelete = (url, callback, err = console.error) => {\n const request = new XMLHttpRequest();\n request.open('DELETE', url, true);\n request.onload = () => callback(request);\n request.onerror = () => err(request);\n request.send();\n};",
|
||||||
"howManyTimes(100, 2); // 2\nhowManyTimes(100, 2.5); // 2\nhowManyTimes(100, 0); // 0\nhowManyTimes(100, -1); // Infinity"
|
"httpDelete('https://website.com/users/123', request => {\n console.log(request.responseText);\n}); // 'Deletes a user from the database'"
|
||||||
],
|
],
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"archived": true,
|
"archived": true,
|
||||||
"hash": "86af9032bb3fd1afc0b6e32aeca6a25c69549594804ff93f9eb0fe6e9e37236b"
|
"hash": "14c205af84a94bb26db5af2bd4b61a5169d48cc90e36e0aea4fae08d24a630c0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,15 +11,16 @@ These snippets, while useful and interesting, didn't quite make it into the repo
|
|||||||
* [`factors`](#factors)
|
* [`factors`](#factors)
|
||||||
* [`fibonacciCountUntilNum`](#fibonaccicountuntilnum)
|
* [`fibonacciCountUntilNum`](#fibonaccicountuntilnum)
|
||||||
* [`fibonacciUntilNum`](#fibonacciuntilnum)
|
* [`fibonacciUntilNum`](#fibonacciuntilnum)
|
||||||
* [`httpDelete`](#httpdelete)
|
* [`howManyTimes`](#howmanytimes)
|
||||||
* [`httpPut`](#httpput)
|
* [`httpPut`](#httpput)
|
||||||
* [`isArmstrongNumber`](#isarmstrongnumber)
|
* [`isArmstrongNumber`](#isarmstrongnumber)
|
||||||
* [`isSimilar`](#issimilar)
|
* [`isSimilar`](#issimilar)
|
||||||
* [`levenshteinDistance`](#levenshteindistance)
|
* [`levenshteinDistance`](#levenshteindistance)
|
||||||
|
* [`pipeLog`](#pipelog)
|
||||||
* [`quickSort`](#quicksort)
|
* [`quickSort`](#quicksort)
|
||||||
* [`removeVowels`](#removevowels)
|
* [`removeVowels`](#removevowels)
|
||||||
* [`solveRPN`](#solverpn)
|
* [`solveRPN`](#solverpn)
|
||||||
* [`howManyTimes`](#howmanytimes)
|
* [`httpDelete`](#httpdelete)
|
||||||
|
|
||||||
---
|
---
|
||||||
### JSONToDate
|
### JSONToDate
|
||||||
@ -282,22 +283,26 @@ fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
### httpDelete
|
### howManyTimes
|
||||||
|
|
||||||
Makes a `DELETE` request to the passed URL.
|
Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer.
|
||||||
|
Works for both negative and positive integers.
|
||||||
|
|
||||||
Use `XMLHttpRequest` web api to make a `delete` request to the given `url`.
|
If `divisor` is `-1` or `1` return `Infinity`.
|
||||||
Handle the `onload` event, by running the provided `callback` function.
|
If `divisor` is `-0` or `0` return `0`.
|
||||||
Handle the `onerror` event, by running the provided `err` function.
|
Otherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer.
|
||||||
Omit the third argument, `err` to log the request to the console's error stream by default.
|
Return the number of times the loop was executed, `i`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const httpDelete = (url, callback, err = console.error) => {
|
const howManyTimes = (num, divisor) => {
|
||||||
const request = new XMLHttpRequest();
|
if (divisor === 1 || divisor === -1) return Infinity;
|
||||||
request.open('DELETE', url, true);
|
if (divisor === 0) return 0;
|
||||||
request.onload = () => callback(request);
|
let i = 0;
|
||||||
request.onerror = () => err(request);
|
while (Number.isInteger(num / divisor)) {
|
||||||
request.send();
|
i++;
|
||||||
|
num = num / divisor;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -305,9 +310,10 @@ const httpDelete = (url, callback, err = console.error) => {
|
|||||||
<summary>Examples</summary>
|
<summary>Examples</summary>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
httpDelete('https://website.com/users/123', request => {
|
howManyTimes(100, 2); // 2
|
||||||
console.log(request.responseText);
|
howManyTimes(100, 2.5); // 2
|
||||||
}); // 'Deletes a user from the database'
|
howManyTimes(100, 0); // 0
|
||||||
|
howManyTimes(100, -1); // Infinity
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@ -454,6 +460,29 @@ compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
### pipeLog
|
||||||
|
|
||||||
|
Logs a value and returns it.
|
||||||
|
|
||||||
|
Use `console.log` to log the supplied value, combined with the `||` operator to return it.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
const pipeLog = data => console.log(data) || data;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
pipeLog(1); // logs `1` and returns `1`
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
### quickSort
|
### quickSort
|
||||||
|
|
||||||
QuickSort an Array (ascending sort by default).
|
QuickSort an Array (ascending sort by default).
|
||||||
@ -561,26 +590,22 @@ solveRPN('2 3 ^'); // 8
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
### howManyTimes
|
### httpDelete
|
||||||
|
|
||||||
Returns the number of times `num` can be divided by `divisor` (integer or fractional) without getting a fractional answer.
|
Makes a `DELETE` request to the passed URL.
|
||||||
Works for both negative and positive integers.
|
|
||||||
|
|
||||||
If `divisor` is `-1` or `1` return `Infinity`.
|
Use `XMLHttpRequest` web api to make a `delete` request to the given `url`.
|
||||||
If `divisor` is `-0` or `0` return `0`.
|
Handle the `onload` event, by running the provided `callback` function.
|
||||||
Otherwise, keep dividing `num` with `divisor` and incrementing `i`, while the result is an integer.
|
Handle the `onerror` event, by running the provided `err` function.
|
||||||
Return the number of times the loop was executed, `i`.
|
Omit the third argument, `err` to log the request to the console's error stream by default.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const howManyTimes = (num, divisor) => {
|
const httpDelete = (url, callback, err = console.error) => {
|
||||||
if (divisor === 1 || divisor === -1) return Infinity;
|
const request = new XMLHttpRequest();
|
||||||
if (divisor === 0) return 0;
|
request.open('DELETE', url, true);
|
||||||
let i = 0;
|
request.onload = () => callback(request);
|
||||||
while (Number.isInteger(num / divisor)) {
|
request.onerror = () => err(request);
|
||||||
i++;
|
request.send();
|
||||||
num = num / divisor;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -588,10 +613,9 @@ const howManyTimes = (num, divisor) => {
|
|||||||
<summary>Examples</summary>
|
<summary>Examples</summary>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
howManyTimes(100, 2); // 2
|
httpDelete('https://website.com/users/123', request => {
|
||||||
howManyTimes(100, 2.5); // 2
|
console.log(request.responseText);
|
||||||
howManyTimes(100, 0); // 0
|
}); // 'Deletes a user from the database'
|
||||||
howManyTimes(100, -1); // Infinity
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
3206
test/testlog
3206
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user