Travis build: 176 [cron]
This commit is contained in:
@ -1494,7 +1494,7 @@
|
||||
"fileName": "filterNonUniqueBy.md",
|
||||
"text": "Filters out the non-unique values in an array, based on a provided comparator function.\n\nUse `Array.filter()` and `Array.every()` for an array containing only the unique values, based on the comparator function, `fn`.\nThe comparator function takes four arguments: the values of the two elements being compared and their indexes.",
|
||||
"codeBlocks": [
|
||||
"const filterNonUniqueBy = (arr, fn) =>\n arr.filter((v, i) => arr.every((x, j) => (i == j) == fn(v, x, i, j)));",
|
||||
"const filterNonUniqueBy = (arr, fn) =>\n arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j)));",
|
||||
"filterNonUniqueBy(\n [\n { id: 0, value: 'a' },\n { id: 1, value: 'b' },\n { id: 2, value: 'c' },\n { id: 1, value: 'd' },\n { id: 0, value: 'e' }\n ],\n (a, b) => a.id == b.id\n); // [ { id: 2, value: 'c' } ]"
|
||||
],
|
||||
"tags": [
|
||||
@ -1504,7 +1504,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": false,
|
||||
"hash": "617e1a689baf11f30c1922cdd94bd7c3b4457aa97c60dcac81b7b2906620cbda"
|
||||
"hash": "39812240e9f09488915843a8ecb6373908513a7a469c00b120779ca462c651c5"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2247,9 +2247,9 @@
|
||||
"type": "snippet",
|
||||
"attributes": {
|
||||
"fileName": "indexOfAll.md",
|
||||
"text": "Returns all indices of `val` in an array. If `val` never occurs, returns `[]`.\n\nUse `Array.forEach()` to loop over elements and `Array.push()` to store indices for matching elements.\nReturn the array of indices.",
|
||||
"text": "Returns all indices of `val` in an array. If `val` never occurs, returns `[]`.\n\nUse `Array.reduce()` to loop over elements and store indices for matching elements.\nReturn the array of indices.",
|
||||
"codeBlocks": [
|
||||
"const indexOfAll = (arr, val) => {\n const indices = [];\n arr.forEach((el, i) => el === val && indices.push(i));\n return indices;\n};",
|
||||
"const indexOfAll = (arr, val) => (arr, val) =>\n arr.reduce((acc, el, i) => (el === val ? [...acc, i] : acc), []);",
|
||||
"indexOfAll([1, 2, 3, 1, 2, 3], 1); // [0,3]\nindexOfAll([1, 2, 3], 4); // []"
|
||||
],
|
||||
"tags": [
|
||||
@ -2258,7 +2258,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": false,
|
||||
"hash": "e2842e376c747f02bce3cddbcbbc55ca9ed8a06701b2e0f4fb4215b97951ff13"
|
||||
"hash": "785b13b5ab3ecdeab0c40e4b4103818daf5e1ef9c2213eb19f9a41d77bfd6734"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -228,14 +228,14 @@
|
||||
"fileName": "levenshteinDistance.md",
|
||||
"text": "Calculates the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings.\n\nCalculates the number of changes (substitutions, deletions or additions) required to convert `string1` to `string2`. \nCan also be used to compare two strings as shown in the second example.",
|
||||
"codeBlocks": [
|
||||
"``` 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).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```",
|
||||
"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 (%)"
|
||||
],
|
||||
"tags": []
|
||||
},
|
||||
"meta": {
|
||||
"archived": true,
|
||||
"hash": "78b4ba08e503af63ca7811cd174218c55db9e0f726439a8c429dedeff0731d80"
|
||||
"hash": "170ef4eafeb5ac639c721f1a8e02d309e1ad62941c613ce60462fa72274f4c25"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -303,7 +303,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": true,
|
||||
"hash": "f654dce947e6e48d66ba5d29452c35c6031e59add0a0124ffed1239317c40ebe"
|
||||
"hash": "878970d0bdefe60f7f61db64b85bbb36b6869e2875a2c278fb269b8cff3b42b4"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user