Travis build: 475 [cron]

This commit is contained in:
30secondsofcode
2018-09-18 20:12:19 +00:00
parent 17a3db8f19
commit 8cf111559d
4 changed files with 1907 additions and 1894 deletions

View File

@ -280,15 +280,15 @@
"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 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]",
@ -303,7 +303,7 @@
},
"meta": {
"archived": true,
"hash": "1f1d7def5d8b149626518181acb9f0e7fd0b44b31e5b42ce1e2f53e07eb01bc0"
"hash": "86af9032bb3fd1afc0b6e32aeca6a25c69549594804ff93f9eb0fe6e9e37236b"
}
},
{

View File

@ -44,7 +44,7 @@ JSONToDate(/Date(1489525200000)/); // "14/3/2017"
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### speechSynthesis
@ -72,7 +72,7 @@ speechSynthesis('Hello, World'); // // plays the message
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### binarySearch
@ -104,7 +104,7 @@ 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
@ -136,7 +136,7 @@ cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}}
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### collatz
@ -157,7 +157,7 @@ collatz(8); // 4
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### countVowels
@ -179,7 +179,7 @@ countVowels('gym'); // 0
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### factors
@ -229,7 +229,7 @@ factors(-12, true); // [2,3]
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### fibonacciCountUntilNum
@ -251,7 +251,7 @@ fibonacciCountUntilNum(10); // 7
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### fibonacciUntilNum
@ -280,7 +280,7 @@ 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();
@ -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
@ -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
@ -373,7 +373,7 @@ isArmstrongNumber(56); // false
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### isSimilar
@ -385,8 +385,14 @@ 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;
(matchIndex, char) =>
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length
? true
: false;
```
<details>
@ -399,7 +405,7 @@ isSimilar('tr','Rohit'); // false
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### levenshteinDistance
@ -412,15 +418,22 @@ Can also be used to compare two strings as shown in the second example.
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);
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);
} else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
}
}
}
@ -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
@ -470,7 +483,7 @@ 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
@ -493,7 +506,7 @@ removeVowels("foobAr","*"); // "f**b*r"
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### solveRPN
@ -546,7 +559,7 @@ solveRPN('2 3 ^'); // 8
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)
### howManyTimes
@ -583,5 +596,5 @@ howManyTimes(100, -1); // Infinity
</details>
[⬆ Back to top](#table-of-contents)
<br>[⬆ Back to top](#table-of-contents)

View File

@ -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(

File diff suppressed because it is too large Load Diff