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
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();

View File

@ -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);
};
```

View File

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

View File

@ -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];
};
```

View File

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