This commit is contained in:
Felix Wu
2018-09-14 15:15:41 +02:00
parent b9817e3344
commit 5727cb4ff0
4 changed files with 2070 additions and 2408 deletions

2394
README.md

File diff suppressed because it is too large Load Diff

6
package-lock.json generated
View File

@ -5696,9 +5696,9 @@
} }
}, },
"markdown-builder": { "markdown-builder": {
"version": "0.8.1", "version": "0.8.3-dev",
"resolved": "https://registry.npmjs.org/markdown-builder/-/markdown-builder-0.8.1.tgz", "resolved": "https://registry.npmjs.org/markdown-builder/-/markdown-builder-0.8.3-dev.tgz",
"integrity": "sha512-zqOAYg8jqUM6gB4WkcJ/K5HkqPUL33VAqNrebHSxlkXcEcjDTeKMNqUC8/bND4tKRu72lRFrTmmGYRtlevvXZQ==", "integrity": "sha512-NJp9MW/odYYP8z1lEEwDW3k+iVnzW1xaJqwWbjlzsAAA1kZohi6Cf3bQkWKZsxPJTZACgYd/aKpmunLSD1u2Bw==",
"requires": { "requires": {
"husky": "1.0.0-rc.14" "husky": "1.0.0-rc.14"
} }

View File

@ -52,7 +52,7 @@
}, },
"homepage": "https://github.com/Chalarangelo/30-seconds-of-code#readme", "homepage": "https://github.com/Chalarangelo/30-seconds-of-code#readme",
"dependencies": { "dependencies": {
"markdown-builder": "^0.8.1" "markdown-builder": "^0.8.3-dev"
}, },
"jest": { "jest": {
"reporters": [ "reporters": [

View File

@ -1,4 +1,4 @@
![Logo](/logo.png "") ![Logo](/logo.png)
# Snippets Archive # Snippets Archive
These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are. These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.
## Table of Contents ## Table of Contents
@ -38,13 +38,12 @@ const JSONToDate = arr => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
JSONToDate(/Date(1489525200000)/); // "14/3/2017" JSONToDate(/Date(1489525200000)/); // "14/3/2017"
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### speechSynthesis ### speechSynthesis
@ -67,13 +66,12 @@ const speechSynthesis = message => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
speechSynthesis('Hello, World'); // // plays the message speechSynthesis('Hello, World'); // // plays the message
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### binarySearch ### binarySearch
@ -99,14 +97,13 @@ const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
<details> <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], 6); // 2
binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1 binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21); // -1
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### cleanObj ### cleanObj
@ -132,14 +129,13 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}} cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}}
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### collatz ### collatz
@ -155,13 +151,12 @@ const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
collatz(8); // 4 collatz(8); // 4
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### countVowels ### countVowels
@ -177,14 +172,13 @@ const countVowels = str => (str.match(/[aeiou]/gi) || []).length;
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
countVowels('foobar'); // 3 countVowels('foobar'); // 3
countVowels('gym'); // 0 countVowels('gym'); // 0
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### factors ### factors
@ -226,7 +220,7 @@ const factors = (num, primes = false) => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
factors(12); // [2,3,4,6,12] factors(12); // [2,3,4,6,12]
factors(12, true); // [2,3] factors(12, true); // [2,3]
factors(-12); // [2, -2, 3, -3, 4, -4, 6, -6, 12, -12] factors(-12); // [2, -2, 3, -3, 4, -4, 6, -6, 12, -12]
@ -235,7 +229,6 @@ factors(-12, true); // [2,3]
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### fibonacciCountUntilNum ### fibonacciCountUntilNum
@ -252,13 +245,12 @@ const fibonacciCountUntilNum = num =>
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
fibonacciCountUntilNum(10); // 7 fibonacciCountUntilNum(10); // 7
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### fibonacciUntilNum ### fibonacciUntilNum
@ -282,13 +274,12 @@ const fibonacciUntilNum = num => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ] fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### httpDelete ### httpDelete
@ -313,7 +304,7 @@ const httpDelete = (url, callback, err = console.error) => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
httpDelete('https://website.com/users/123', request => { httpDelete('https://website.com/users/123', request => {
console.log(request.responseText); console.log(request.responseText);
}); // 'Deletes a user from the database' }); // 'Deletes a user from the database'
@ -321,7 +312,6 @@ httpDelete('https://website.com/users/123', request => {
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### httpPut ### httpPut
@ -348,7 +338,7 @@ const httpPut = (url, data, callback, err = console.error) => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
const password = "fooBaz"; const password = "fooBaz";
const data = JSON.stringify(password); const data = JSON.stringify(password);
httpPut('https://website.com/users/123', data, request => { httpPut('https://website.com/users/123', data, request => {
@ -358,7 +348,6 @@ httpPut('https://website.com/users/123', data, request => {
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### isArmstrongNumber ### isArmstrongNumber
@ -377,14 +366,13 @@ const isArmstrongNumber = digits =>
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
isArmstrongNumber(1634); // true isArmstrongNumber(1634); // true
isArmstrongNumber(56); // false isArmstrongNumber(56); // false
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### isSimilar ### isSimilar
@ -404,14 +392,13 @@ const isSimilar = (pattern, str) =>
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
isSimilar('rt','Rohit'); // true isSimilar('rt','Rohit'); // true
isSimilar('tr','Rohit'); // false isSimilar('tr','Rohit'); // false
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### levenshteinDistance ### levenshteinDistance
@ -444,7 +431,7 @@ const levenshteinDistance = (string1, string2) => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7 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)); 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 (%) compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)
@ -452,7 +439,6 @@ compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### quickSort ### quickSort
@ -477,14 +463,13 @@ const quickSort = ([n, ...nums], desc) =>
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
quickSort([4, 1, 3, 2]); // [1,2,3,4] quickSort([4, 1, 3, 2]); // [1,2,3,4]
quickSort([4, 1, 3, 2], true); // [4,3,2,1] quickSort([4, 1, 3, 2], true); // [4,3,2,1]
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### removeVowels ### removeVowels
@ -501,14 +486,13 @@ const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl);
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
removeVowels("foobAr"); // "fbr" removeVowels("foobAr"); // "fbr"
removeVowels("foobAr","*"); // "f**b*r" removeVowels("foobAr","*"); // "f**b*r"
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### solveRPN ### solveRPN
@ -555,14 +539,13 @@ const solveRPN = rpn => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5 solveRPN('15 7 1 1 + - / 3 * 2 1 1 + + -'); // 5
solveRPN('2 3 ^'); // 8 solveRPN('2 3 ^'); // 8
``` ```
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)
### howManyTimes ### howManyTimes
@ -591,7 +574,7 @@ const howManyTimes = (num, divisor) => {
<details> <details>
<summary>Examples</summary> <summary>Examples</summary>
```js ```js
howManyTimes(100, 2); // 2 howManyTimes(100, 2); // 2
howManyTimes(100, 2.5); // 2 howManyTimes(100, 2.5); // 2
howManyTimes(100, 0); // 0 howManyTimes(100, 0); // 0
@ -600,6 +583,5 @@ howManyTimes(100, -1); // Infinity
</details> </details>
[⬆ Back to top](#table-of-contents) [⬆ Back to top](#table-of-contents)