Travis build: 475 [cron]
This commit is contained in:
@ -280,19 +280,19 @@
|
||||
"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};",
|
||||
"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 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};",
|
||||
"httpDelete('https://website.com/users/123', request => {\n console.log(request.responseText);\n}); // 'Deletes a user from the database'",
|
||||
"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 isArmstrongNumber = digits =>\n (arr => arr.reduce((a, d) => a + parseInt(d) ** arr.length, 0) == digits)(\n (digits + '').split('')\n );",
|
||||
"isArmstrongNumber(1634); // true\nisArmstrongNumber(56); // false",
|
||||
"const isSimilar = (pattern, str) =>\n\t[...str].reduce(\n\t\t(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0\n\t) === pattern.length ? true : false;",
|
||||
"const isSimilar = (pattern, str) =>\n [...str].reduce(\n (matchIndex, char) =>\n char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()\n ? matchIndex + 1\n : matchIndex,\n 0\n ) === pattern.length\n ? true\n : 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).fill(0).map((x,i) => [i]);\n matrix[0] = Array(string1.length + 1).fill(0).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 }\n else{\n matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1);\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 (%)",
|
||||
"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]",
|
||||
"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\"",
|
||||
"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",
|
||||
@ -303,7 +303,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": true,
|
||||
"hash": "1f1d7def5d8b149626518181acb9f0e7fd0b44b31e5b42ce1e2f53e07eb01bc0"
|
||||
"hash": "86af9032bb3fd1afc0b6e32aeca6a25c69549594804ff93f9eb0fe6e9e37236b"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -36,15 +36,15 @@ const JSONToDate = arr => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
JSONToDate(/Date(1489525200000)/); // "14/3/2017"
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### speechSynthesis
|
||||
|
||||
@ -64,15 +64,15 @@ const speechSynthesis = message => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
speechSynthesis('Hello, World'); // // plays the message
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### binarySearch
|
||||
|
||||
@ -95,16 +95,16 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6); // 2
|
||||
binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### cleanObj
|
||||
|
||||
@ -127,16 +127,16 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
|
||||
cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### collatz
|
||||
|
||||
@ -149,15 +149,15 @@ const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
collatz(8); // 4
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### countVowels
|
||||
|
||||
@ -170,16 +170,16 @@ const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
countVowels('foobar'); // 3
|
||||
countVowels('gym'); // 0
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### factors
|
||||
|
||||
@ -218,9 +218,9 @@ const factors = (num, primes = false) => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
factors(12); // [2,3,4,6,12]
|
||||
factors(12, true); // [2,3]
|
||||
factors(-12); // [2, -2, 3, -3, 4, -4, 6, -6, 12, -12]
|
||||
@ -229,7 +229,7 @@ factors(-12, true); // [2,3]
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### fibonacciCountUntilNum
|
||||
|
||||
@ -243,15 +243,15 @@ const fibonacciCountUntilNum = num =>
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
fibonacciCountUntilNum(10); // 7
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### fibonacciUntilNum
|
||||
|
||||
@ -272,15 +272,15 @@ const fibonacciUntilNum = num => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### httpDelete
|
||||
|
||||
@ -294,7 +294,7 @@ Omit the third argument, `err` to log the request to the console's error stream
|
||||
```js
|
||||
const httpDelete = (url, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("DELETE", url, true);
|
||||
request.open('DELETE', url, true);
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send();
|
||||
@ -302,9 +302,9 @@ const httpDelete = (url, callback, err = console.error) => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
httpDelete('https://website.com/users/123', request => {
|
||||
console.log(request.responseText);
|
||||
}); // 'Deletes a user from the database'
|
||||
@ -312,7 +312,7 @@ httpDelete('https://website.com/users/123', request => {
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### httpPut
|
||||
|
||||
@ -326,19 +326,19 @@ Omit the last argument, `err` to log the request to the console's error stream b
|
||||
|
||||
```js
|
||||
const httpPut = (url, data, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
const password = "fooBaz";
|
||||
const data = JSON.stringify(password);
|
||||
httpPut('https://website.com/users/123', data, request => {
|
||||
@ -348,7 +348,7 @@ httpPut('https://website.com/users/123', data, request => {
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### isArmstrongNumber
|
||||
|
||||
@ -364,16 +364,16 @@ const isArmstrongNumber = digits =>
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
isArmstrongNumber(1634); // true
|
||||
isArmstrongNumber(56); // false
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### isSimilar
|
||||
|
||||
@ -384,22 +384,28 @@ Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db5
|
||||
|
||||
```js
|
||||
const isSimilar = (pattern, str) =>
|
||||
[...str].reduce(
|
||||
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
|
||||
) === pattern.length ? true : false;
|
||||
[...str].reduce(
|
||||
(matchIndex, char) =>
|
||||
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
||||
? matchIndex + 1
|
||||
: matchIndex,
|
||||
0
|
||||
) === pattern.length
|
||||
? true
|
||||
: false;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
isSimilar('rt','Rohit'); // true
|
||||
isSimilar('tr','Rohit'); // false
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### levenshteinDistance
|
||||
|
||||
@ -410,28 +416,35 @@ Can also be used to compare two strings as shown in the second example.
|
||||
|
||||
``` js
|
||||
const levenshteinDistance = (string1, string2) => {
|
||||
if(string1.length === 0) return string2.length;
|
||||
if(string2.length === 0) return string1.length;
|
||||
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]);
|
||||
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i);
|
||||
for(let i = 1; i <= string2.length; i++) {
|
||||
for(let j = 1; j<=string1.length; j++) {
|
||||
if(string2[i-1] === string1[j-1]) {
|
||||
matrix[i][j] = matrix[i-1][j-1];
|
||||
}
|
||||
else{
|
||||
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1);
|
||||
}
|
||||
}
|
||||
if (string1.length === 0) return string2.length;
|
||||
if (string2.length === 0) return string1.length;
|
||||
let matrix = Array(string2.length + 1)
|
||||
.fill(0)
|
||||
.map((x, i) => [i]);
|
||||
matrix[0] = Array(string1.length + 1)
|
||||
.fill(0)
|
||||
.map((x, i) => i);
|
||||
for (let i = 1; i <= string2.length; i++) {
|
||||
for (let j = 1; j <= string1.length; j++) {
|
||||
if (string2[i - 1] === string1[j - 1]) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1];
|
||||
} else {
|
||||
matrix[i][j] = Math.min(
|
||||
matrix[i - 1][j - 1] + 1,
|
||||
matrix[i][j - 1] + 1,
|
||||
matrix[i - 1][j] + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
return matrix[string2.length][string1.length];
|
||||
}
|
||||
return matrix[string2.length][string1.length];
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7
|
||||
const compareStrings = (string1,string2) => (100 - levenshteinDistance(string1,string2) / Math.max(string1.length,string2.length));
|
||||
compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)
|
||||
@ -439,7 +452,7 @@ compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### quickSort
|
||||
|
||||
@ -461,16 +474,16 @@ const quickSort = ([n, ...nums], desc) =>
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
quickSort([4, 1, 3, 2]); // [1,2,3,4]
|
||||
quickSort([4, 1, 3, 2], true); // [4,3,2,1]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### removeVowels
|
||||
|
||||
@ -480,20 +493,20 @@ Use `String.replace()` with a regexp to replace all vowels in `str`.
|
||||
Omot `repl` to use a default value of `''`.
|
||||
|
||||
```js
|
||||
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl);
|
||||
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
removeVowels("foobAr"); // "fbr"
|
||||
removeVowels("foobAr","*"); // "f**b*r"
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### solveRPN
|
||||
|
||||
@ -537,16 +550,16 @@ const solveRPN = rpn => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5
|
||||
solveRPN('2 3 ^'); // 8
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### howManyTimes
|
||||
|
||||
@ -572,9 +585,9 @@ const howManyTimes = (num, divisor) => {
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
```js
|
||||
howManyTimes(100, 2); // 2
|
||||
howManyTimes(100, 2.5); // 2
|
||||
howManyTimes(100, 0); // 0
|
||||
@ -583,5 +596,5 @@ howManyTimes(100, -1); // Infinity
|
||||
|
||||
</details>
|
||||
|
||||
[⬆ Back to top](#table-of-contents)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const observeMutations = (element, callback, options) => {
|
||||
const observer = new MutationObserver(mutations => mutations.forEach(callback));
|
||||
const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
|
||||
observer.observe(
|
||||
element,
|
||||
Object.assign(
|
||||
|
||||
3496
test/testlog
3496
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user