diff --git a/scripts/localize.js b/scripts/localize.js index 547a00d18..261a55d15 100644 --- a/scripts/localize.js +++ b/scripts/localize.js @@ -58,6 +58,6 @@ locales.forEach(locale => { fs.writeFileSync( path.join(LOCALE_PATH, locale + '_log'), `${new Date()}\nHash changes: ${hashChanges.length}\n${ - hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n'): ''}` + hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n') : ''}` ); }); diff --git a/snippets_archive/httpDelete.md b/snippets_archive/httpDelete.md index 34a42d5df..0b95fd2ff 100644 --- a/snippets_archive/httpDelete.md +++ b/snippets_archive/httpDelete.md @@ -10,7 +10,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(); diff --git a/snippets_archive/httpPut.md b/snippets_archive/httpPut.md index 4f9dbd785..400f5dcd3 100644 --- a/snippets_archive/httpPut.md +++ b/snippets_archive/httpPut.md @@ -10,12 +10,12 @@ 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); }; ``` diff --git a/snippets_archive/isSimilar.md b/snippets_archive/isSimilar.md index e6b2a8360..a6c894361 100644 --- a/snippets_archive/isSimilar.md +++ b/snippets_archive/isSimilar.md @@ -7,9 +7,15 @@ 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; ``` ```js diff --git a/snippets_archive/levenshteinDistance.md b/snippets_archive/levenshteinDistance.md index 4ab2a0d3a..85012adb0 100644 --- a/snippets_archive/levenshteinDistance.md +++ b/snippets_archive/levenshteinDistance.md @@ -7,21 +7,28 @@ 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]; }; ``` diff --git a/snippets_archive/removeVowels.md b/snippets_archive/removeVowels.md index e3558cb36..61321fb71 100644 --- a/snippets_archive/removeVowels.md +++ b/snippets_archive/removeVowels.md @@ -6,7 +6,7 @@ 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); ``` ```js diff --git a/test/httpDelete/httpDelete.js b/test/httpDelete/httpDelete.js index 2a2d55a28..5b86d324a 100644 --- a/test/httpDelete/httpDelete.js +++ b/test/httpDelete/httpDelete.js @@ -1,6 +1,6 @@ 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(); diff --git a/test/httpPut/httpPut.js b/test/httpPut/httpPut.js index 9c34ca2d0..4b3e02701 100644 --- a/test/httpPut/httpPut.js +++ b/test/httpPut/httpPut.js @@ -1,9 +1,9 @@ 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); }; module.exports = httpPut; diff --git a/test/isSimilar/isSimilar.js b/test/isSimilar/isSimilar.js index b8f7f2f69..7b0c9e77c 100644 --- a/test/isSimilar/isSimilar.js +++ b/test/isSimilar/isSimilar.js @@ -1,5 +1,11 @@ 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; module.exports = isSimilar; diff --git a/test/levenshteinDistance/levenshteinDistance.js b/test/levenshteinDistance/levenshteinDistance.js index 9afe5fbc0..d9a76b41d 100644 --- a/test/levenshteinDistance/levenshteinDistance.js +++ b/test/levenshteinDistance/levenshteinDistance.js @@ -1,18 +1,25 @@ 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]; }; module.exports = levenshteinDistance; diff --git a/test/removeVowels/removeVowels.js b/test/removeVowels/removeVowels.js index 1614fa7ce..31250b816 100644 --- a/test/removeVowels/removeVowels.js +++ b/test/removeVowels/removeVowels.js @@ -1,2 +1,2 @@ -const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl); +const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl); module.exports = removeVowels;