Travis build: 1666
This commit is contained in:
@ -835,7 +835,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "5ab25ab96afd4f1f481fc318b5b290ba8c57a468ef6bca0ca200cfb7fcf3ba9f"
|
||||
"hash": "77a01af8797ecbe71b9c9412d21c144c03a46a49dd3d0e7d869c3df38b39b2b4"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -898,7 +898,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "7a228b650ff668f697e524e0d27ebeff1bfa35e04333b6cd5e742ff63bfea25d"
|
||||
"hash": "6fa14364405f7b99aa49c2157bdc08c02b4ce2f288db29a4348a6983460933c7"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -1037,7 +1037,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "5f38360819f9225b887a94221bfee1a80f1bcc224a364440b3388f60491b03ba"
|
||||
"hash": "bdc202436bee09f06a353d31841c6cfff33e8efead34c6c56ae1a1413284976d"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -1273,7 +1273,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "55b1ce0a892110d792a9487e40331774015525479faa2b8961f6c2ea6291c27b"
|
||||
"hash": "6e9710c9117f500e74e65c0ee36b39fb80bd55537fa5ff9c4b1136b2667096f2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -1678,7 +1678,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "16c3b724b653dcb31f3e59f1664a59951abb15a93eb3697cade4d3ae0e63c532"
|
||||
"hash": "f9e6687cc28cd80e68f7a6776f893c7478aaa942710e0eb7144f105eba574a54"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2864,7 +2864,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "362fddaa6244404741e84bca6fc442a101fdb642af53b299e8b9994d0d7162d8"
|
||||
"hash": "3db3faac666ee61ab86c70766d2ab5d1293ffd818da87edb971bfff7a366364a"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -3425,7 +3425,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "b031c3387ef66411ab5d295788eac4247ada5b4b068dda90603d3c973890bc26"
|
||||
"hash": "e8f820ce6da97eabde082ffb829c9fb700e85efc79bdebe883c67237269e3f52"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -3774,7 +3774,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "17bcf3f13980b7f804d9f0fe274324b2a35ab7d479c03d77322dabba81e1a34a"
|
||||
"hash": "7ccbf66d8d55c60bcf12baa980cf32d67a4ba567894d59e2d798c9af792424ff"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -4171,7 +4171,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "069472d018c3102412dafc2ae8ec6e9396e53c01d0073079f2e3f1ac3c99b6e9"
|
||||
"hash": "c1542907e6295eb81df918174c247a65d73c8daccc56769f2eb32d609b7846fc"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -4487,7 +4487,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "24b93b68a59b49f245590930fed6fb82e286ce09f90e292466cde63c1784c347"
|
||||
"hash": "6dd4c6a51d2c80fa4768c95ae01c16a8359c4140bcad28c7fde0cecd72d7d3e2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -5483,7 +5483,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "6bba5ca7427489cdf18476542772743ae2d5f4eccb42ff93ee61b9f8ba1f55d6"
|
||||
"hash": "94d3b2ea296a94907be873c19381a525eeb96676cd52cb1baf1bd76bc22971a6"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -1361,7 +1361,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "5ab25ab96afd4f1f481fc318b5b290ba8c57a468ef6bca0ca200cfb7fcf3ba9f",
|
||||
"hash": "77a01af8797ecbe71b9c9412d21c144c03a46a49dd3d0e7d869c3df38b39b2b4",
|
||||
"firstSeen": "1516733326",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 54,
|
||||
@ -1464,7 +1464,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "7a228b650ff668f697e524e0d27ebeff1bfa35e04333b6cd5e742ff63bfea25d",
|
||||
"hash": "6fa14364405f7b99aa49c2157bdc08c02b4ce2f288db29a4348a6983460933c7",
|
||||
"firstSeen": "1544374334\n1543497773",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 68,
|
||||
@ -1693,7 +1693,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "5f38360819f9225b887a94221bfee1a80f1bcc224a364440b3388f60491b03ba",
|
||||
"hash": "bdc202436bee09f06a353d31841c6cfff33e8efead34c6c56ae1a1413284976d",
|
||||
"firstSeen": "1531080384",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 88,
|
||||
@ -2079,7 +2079,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "55b1ce0a892110d792a9487e40331774015525479faa2b8961f6c2ea6291c27b",
|
||||
"hash": "6e9710c9117f500e74e65c0ee36b39fb80bd55537fa5ff9c4b1136b2667096f2",
|
||||
"firstSeen": "1512650493",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 93,
|
||||
@ -2744,7 +2744,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "16c3b724b653dcb31f3e59f1664a59951abb15a93eb3697cade4d3ae0e63c532",
|
||||
"hash": "f9e6687cc28cd80e68f7a6776f893c7478aaa942710e0eb7144f105eba574a54",
|
||||
"firstSeen": "1515856488",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 50,
|
||||
@ -4680,7 +4680,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "362fddaa6244404741e84bca6fc442a101fdb642af53b299e8b9994d0d7162d8",
|
||||
"hash": "3db3faac666ee61ab86c70766d2ab5d1293ffd818da87edb971bfff7a366364a",
|
||||
"firstSeen": "1514801920",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 56,
|
||||
@ -5591,7 +5591,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "b031c3387ef66411ab5d295788eac4247ada5b4b068dda90603d3c973890bc26",
|
||||
"hash": "e8f820ce6da97eabde082ffb829c9fb700e85efc79bdebe883c67237269e3f52",
|
||||
"firstSeen": "1570824965",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 23,
|
||||
@ -6150,7 +6150,7 @@
|
||||
"codeBlocks": {
|
||||
"es6": "const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));",
|
||||
"es5": "var pipeAsyncFunctions = function pipeAsyncFunctions() {\n for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {\n fns[_key] = arguments[_key];\n }\n\n return function (arg) {\n return fns.reduce(function (p, f) {\n return p.then(f);\n }, Promise.resolve(arg));\n };\n};",
|
||||
"example": "const sum = pipeAsyncFunctions(\n x => x + 1,\n x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),\n x => x + 3,\n async x => (await x) + 4\n);\n(async() => {\n console.log(await sum(5)); // 15 (after one second)\n})();"
|
||||
"example": "const sum = pipeAsyncFunctions(\n x => x + 1,\n x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),\n x => x + 3,\n async x => (await x) + 4\n);\n(async () => {\n console.log(await sum(5)); // 15 (after one second)\n})();"
|
||||
},
|
||||
"tags": [
|
||||
"adapter",
|
||||
@ -6160,7 +6160,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "17bcf3f13980b7f804d9f0fe274324b2a35ab7d479c03d77322dabba81e1a34a",
|
||||
"hash": "7ccbf66d8d55c60bcf12baa980cf32d67a4ba567894d59e2d798c9af792424ff",
|
||||
"firstSeen": "1517069864",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 80,
|
||||
@ -6807,7 +6807,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "069472d018c3102412dafc2ae8ec6e9396e53c01d0073079f2e3f1ac3c99b6e9",
|
||||
"hash": "c1542907e6295eb81df918174c247a65d73c8daccc56769f2eb32d609b7846fc",
|
||||
"firstSeen": "1513521691",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 77,
|
||||
@ -7323,7 +7323,7 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "24b93b68a59b49f245590930fed6fb82e286ce09f90e292466cde63c1784c347",
|
||||
"hash": "6dd4c6a51d2c80fa4768c95ae01c16a8359c4140bcad28c7fde0cecd72d7d3e2",
|
||||
"firstSeen": "1514645161",
|
||||
"lastUpdated": "1577431401",
|
||||
"updateCount": 22,
|
||||
@ -8938,7 +8938,7 @@
|
||||
"fileName": "weightedSample.md",
|
||||
"text": "Returns a random element from an array, using the provided `weights` as the probabilities for each element.\n\nUse `Array.prototype.reduce()` to create an array of partial sums for each value in `weights`.\nUse `Math.random()` to generate a random number and `Array.prototype.findIndex()` to find the correct index based on the array previously produced.\nFinally, return the element of `arr` with the produced index.\n\n\n",
|
||||
"codeBlocks": {
|
||||
"es6": "const weightedSample = (arr, weights) => {\n let roll = Math.random();\n return arr[\n weights\n .reduce((acc, w, i) =>\n i === 0 ? [w] : [...acc, acc[acc.length - 1] + w],\n []\n )\n .findIndex((v, i, s) =>\n roll >= (i === 0 ? 0 : s[i - 1]) && roll < v\n )\n ];\n}",
|
||||
"es6": "const weightedSample = (arr, weights) => {\n let roll = Math.random();\n return arr[\n weights\n .reduce((acc, w, i) => (i === 0 ? [w] : [...acc, acc[acc.length - 1] + w]), [])\n .findIndex((v, i, s) => roll >= (i === 0 ? 0 : s[i - 1]) && roll < v)\n ];\n};",
|
||||
"es5": "function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance\"); }\n\nfunction _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }\n\nvar weightedSample = function weightedSample(arr, weights) {\n var roll = Math.random();\n return arr[weights.reduce(function (acc, w, i) {\n return i === 0 ? [w] : [].concat(_toConsumableArray(acc), [acc[acc.length - 1] + w]);\n }, []).findIndex(function (v, i, s) {\n return roll >= (i === 0 ? 0 : s[i - 1]) && roll < v;\n })];\n};",
|
||||
"example": "weightedSample([3, 7, 9, 11], [0.1, 0.2, 0.6, 0.1]); // 9"
|
||||
},
|
||||
@ -8949,11 +8949,11 @@
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "6bba5ca7427489cdf18476542772743ae2d5f4eccb42ff93ee61b9f8ba1f55d6",
|
||||
"firstSeen": "",
|
||||
"lastUpdated": "",
|
||||
"updateCount": 1,
|
||||
"authorCount": 1
|
||||
"hash": "94d3b2ea296a94907be873c19381a525eeb96676cd52cb1baf1bd76bc22971a6",
|
||||
"firstSeen": "1577784866",
|
||||
"lastUpdated": "1577784866",
|
||||
"updateCount": 2,
|
||||
"authorCount": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -11,7 +11,6 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th
|
||||
Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
|
||||
|
||||
```js
|
||||
|
||||
const deepClone = obj => {
|
||||
if (obj === null) return null;
|
||||
let clone = Object.assign({}, obj);
|
||||
|
||||
@ -10,7 +10,6 @@ Use `Object.keys(obj)` to iterate over the object's keys.
|
||||
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
||||
|
||||
```js
|
||||
|
||||
const deepMapKeys = (obj, f) =>
|
||||
Array.isArray(obj)
|
||||
? obj.map(val => deepMapKeys(val, f))
|
||||
|
||||
@ -9,7 +9,6 @@ Use the `in` operator to check if `target` exists in `obj`.
|
||||
If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
|
||||
|
||||
```js
|
||||
|
||||
const dig = (obj, target) =>
|
||||
target in obj
|
||||
? obj[target]
|
||||
|
||||
@ -11,7 +11,6 @@ Otherwise, return the product of `n` and the factorial of `n - 1`.
|
||||
Throws an exception if `n` is a negative number.
|
||||
|
||||
```js
|
||||
|
||||
const factorial = n =>
|
||||
n < 0
|
||||
? (() => {
|
||||
|
||||
@ -8,7 +8,6 @@ Converts an integer to a suffixed string, adding `am` or `pm` based on its value
|
||||
Use the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
|
||||
|
||||
```js
|
||||
|
||||
const getMeridiemSuffixOfInteger = num =>
|
||||
num === 0 || num === 24
|
||||
? 12 + 'am'
|
||||
|
||||
@ -11,7 +11,6 @@ Omit the second argument, `separator`, to use a default separator of `','`.
|
||||
Omit the third argument, `end`, to use the same value as `separator` by default.
|
||||
|
||||
```js
|
||||
|
||||
const join = (arr, separator = ',', end = separator) =>
|
||||
arr.reduce(
|
||||
(acc, val, i) =>
|
||||
|
||||
@ -10,7 +10,6 @@ Determine the `symbol` to be either `?` or `&` based on the `length` of `querySt
|
||||
Return the `queryString` or an empty string when the `queryParameters` are falsy.
|
||||
|
||||
```js
|
||||
|
||||
const objectToQueryString = queryParameters => {
|
||||
return queryParameters
|
||||
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
|
||||
|
||||
@ -14,14 +14,13 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
const sum = pipeAsyncFunctions(
|
||||
x => x + 1,
|
||||
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
|
||||
x => x + 3,
|
||||
async x => (await x) + 4
|
||||
);
|
||||
(async() => {
|
||||
(async () => {
|
||||
console.log(await sum(5)); // 15 (after one second)
|
||||
})();
|
||||
```
|
||||
@ -9,6 +9,7 @@ Use `Array.prototype.filter()` to find array elements that return truthy values
|
||||
The `func` is invoked with three arguments (`value, index, array`).
|
||||
|
||||
```js
|
||||
|
||||
const remove = (arr, func) =>
|
||||
Array.isArray(arr)
|
||||
? arr.filter(func).reduce((acc, val) => {
|
||||
|
||||
@ -12,7 +12,6 @@ Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API
|
||||
Split strings into array of characters with `split('')` and return its length.
|
||||
|
||||
```js
|
||||
|
||||
const size = val =>
|
||||
Array.isArray(val)
|
||||
? val.length
|
||||
|
||||
@ -15,15 +15,10 @@ const weightedSample = (arr, weights) => {
|
||||
let roll = Math.random();
|
||||
return arr[
|
||||
weights
|
||||
.reduce((acc, w, i) =>
|
||||
i === 0 ? [w] : [...acc, acc[acc.length - 1] + w],
|
||||
[]
|
||||
)
|
||||
.findIndex((v, i, s) =>
|
||||
roll >= (i === 0 ? 0 : s[i - 1]) && roll < v
|
||||
)
|
||||
.reduce((acc, w, i) => (i === 0 ? [w] : [...acc, acc[acc.length - 1] + w]), [])
|
||||
.findIndex((v, i, s) => roll >= (i === 0 ? 0 : s[i - 1]) && roll < v)
|
||||
];
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
11
test/_30s.js
11
test/_30s.js
@ -1379,15 +1379,10 @@ const weightedSample = (arr, weights) => {
|
||||
let roll = Math.random();
|
||||
return arr[
|
||||
weights
|
||||
.reduce((acc, w, i) =>
|
||||
i === 0 ? [w] : [...acc, acc[acc.length - 1] + w],
|
||||
[]
|
||||
)
|
||||
.findIndex((v, i, s) =>
|
||||
roll >= (i === 0 ? 0 : s[i - 1]) && roll < v
|
||||
)
|
||||
.reduce((acc, w, i) => (i === 0 ? [w] : [...acc, acc[acc.length - 1] + w]), [])
|
||||
.findIndex((v, i, s) => roll >= (i === 0 ? 0 : s[i - 1]) && roll < v)
|
||||
];
|
||||
}
|
||||
};
|
||||
const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x);
|
||||
const without = (arr, ...args) => arr.filter(v => !args.includes(v));
|
||||
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);
|
||||
|
||||
@ -3449,6 +3449,20 @@
|
||||
],
|
||||
"description": "Returns the distance between two vectors.\n\nUse `Array.prototype.reduce()`, `Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors.\n"
|
||||
},
|
||||
"weightedSample": {
|
||||
"prefix": "30s_weightedSample",
|
||||
"body": [
|
||||
"const weightedSample = (arr, weights) => {",
|
||||
" let roll = Math.random();",
|
||||
" return arr[",
|
||||
" weights",
|
||||
" .reduce((acc, w, i) => (i === 0 ? [w] : [...acc, acc[acc.length - 1] + w]), [])",
|
||||
" .findIndex((v, i, s) => roll >= (i === 0 ? 0 : s[i - 1]) && roll < v)",
|
||||
" ];",
|
||||
"};"
|
||||
],
|
||||
"description": "Returns a random element from an array, using the provided `weights` as the probabilities for each element.\n\nUse `Array.prototype.reduce()` to create an array of partial sums for each value in `weights`.\nUse `Math.random()` to generate a random number and `Array.prototype.findIndex()` to find the correct index based on the array previously produced.\nFinally, return the element of `arr` with the produced index.\n\n"
|
||||
},
|
||||
"when": {
|
||||
"prefix": "30s_when",
|
||||
"body": [
|
||||
|
||||
Reference in New Issue
Block a user