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"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user