Linted archive

This commit is contained in:
Angelos Chalaris
2018-09-15 13:52:12 +03:00
parent 3a887a67f4
commit 2ba4b95b47
11 changed files with 77 additions and 51 deletions

View File

@ -10,7 +10,7 @@ Omit the third argument, `err` to log the request to the console's error stream
```js ```js
const httpDelete = (url, callback, err = console.error) => { const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("DELETE", url, true); request.open('DELETE', url, true);
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(); request.send();

View File

@ -8,8 +8,14 @@ Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db5
```js ```js
const isSimilar = (pattern, str) => const isSimilar = (pattern, str) =>
[...str].reduce( [...str].reduce(
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0 (matchIndex, char) =>
) === pattern.length ? true : false; char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length
? true
: false;
``` ```
```js ```js

View File

@ -9,15 +9,22 @@ Can also be used to compare two strings as shown in the second example.
const levenshteinDistance = (string1, string2) => { const levenshteinDistance = (string1, string2) => {
if (string1.length === 0) return string2.length; if (string1.length === 0) return string2.length;
if (string2.length === 0) return string1.length; if (string2.length === 0) return string1.length;
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); let matrix = Array(string2.length + 1)
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); .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 i = 1; i <= string2.length; i++) {
for (let j = 1; j <= string1.length; j++) { for (let j = 1; j <= string1.length; j++) {
if (string2[i - 1] === string1[j - 1]) { if (string2[i - 1] === string1[j - 1]) {
matrix[i][j] = matrix[i - 1][j - 1]; matrix[i][j] = matrix[i - 1][j - 1];
} } else {
else{ matrix[i][j] = Math.min(
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1); matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
} }
} }
} }

View File

@ -1,6 +1,6 @@
const httpDelete = (url, callback, err = console.error) => { const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("DELETE", url, true); request.open('DELETE', url, true);
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(); request.send();

View File

@ -1,6 +1,6 @@
const httpPut = (url, data, callback, err = console.error) => { const httpPut = (url, data, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("PUT", url, true); request.open('PUT', url, true);
request.setRequestHeader('Content-type', 'application/json; charset=utf-8'); request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);

View File

@ -1,5 +1,11 @@
const isSimilar = (pattern, str) => const isSimilar = (pattern, str) =>
[...str].reduce( [...str].reduce(
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0 (matchIndex, char) =>
) === pattern.length ? true : false; char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length
? true
: false;
module.exports = isSimilar; module.exports = isSimilar;

View File

@ -1,15 +1,22 @@
const levenshteinDistance = (string1, string2) => { const levenshteinDistance = (string1, string2) => {
if (string1.length === 0) return string2.length; if (string1.length === 0) return string2.length;
if (string2.length === 0) return string1.length; if (string2.length === 0) return string1.length;
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); let matrix = Array(string2.length + 1)
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); .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 i = 1; i <= string2.length; i++) {
for (let j = 1; j <= string1.length; j++) { for (let j = 1; j <= string1.length; j++) {
if (string2[i - 1] === string1[j - 1]) { if (string2[i - 1] === string1[j - 1]) {
matrix[i][j] = matrix[i - 1][j - 1]; matrix[i][j] = matrix[i - 1][j - 1];
} } else {
else{ matrix[i][j] = Math.min(
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1); matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
} }
} }
} }