Travis build: 1021 [cron]

This commit is contained in:
30secondsofcode
2019-02-25 15:09:51 +00:00
parent ffc7d2aeb8
commit e1d6a8f9af
7 changed files with 136 additions and 61 deletions

View File

@ -533,11 +533,11 @@
" ? obj.map(val => deepMapKeys(val, f))",
" : typeof obj === 'object'",
" ? Object.keys(obj).reduce((acc, current) => {",
" const val = obj[current];",
" acc[f(current)] =",
" const val = obj[current];",
" acc[f(current)] =",
" val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);",
" return acc;",
" }, {})",
" return acc;",
" }, {})",
" : obj;"
],
"description": "Deep maps an object keys.\n\nCreates an object with the same values as the provided object and keys generated by running the provided function for each key.\n\nUse `Object.keys(obj)` to iterate over the object's keys. \nUse `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`"
@ -614,9 +614,9 @@
" target in obj",
" ? obj[target]",
" : Object.values(obj).reduce((acc, val) => {",
" if (acc !== undefined) return acc;",
" if (typeof val === 'object') return dig(val, target);",
" }, undefined);"
" if (acc !== undefined) return acc;",
" if (typeof val === 'object') return dig(val, target);",
" }, undefined);"
],
"description": "Returns the target value in a nested JSON object, based on the given key.\n\nUse the `in` operator to check if `target` exists in `obj`.\nIf 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"
},
@ -778,8 +778,8 @@
"const factorial = n =>",
" n < 0",
" ? (() => {",
" throw new TypeError('Negative numbers are not allowed!');",
" })()",
" throw new TypeError('Negative numbers are not allowed!');",
" })()",
" : n <= 1",
" ? 1",
" : n * factorial(n - 1);"
@ -2490,9 +2490,9 @@
"const remove = (arr, func) =>",
" Array.isArray(arr)",
" ? arr.filter(func).reduce((acc, val) => {",
" arr.splice(arr.indexOf(val), 1);",
" return acc.concat(val);",
" }, [])",
" arr.splice(arr.indexOf(val), 1);",
" return acc.concat(val);",
" }, [])",
" : [];"
],
"description": "Removes elements from an array for which the given function returns `false`.\n\nUse `Array.prototype.filter()` to find array elements that return truthy values and `Array.prototype.reduce()` to remove elements using `Array.prototype.splice()`.\nThe `func` is invoked with three arguments (`value, index, array`)"
@ -3328,6 +3328,19 @@
],
"description": "Returns `true` if the given value is a number, `false` otherwise.\n\nUse `!isNaN()` in combination with `parseFloat()` to check if the argument is a number.\nUse `isFinite()` to check if the number is finite.\nUse `Number()` to check if the coercion holds"
},
"vectorDistance": {
"prefix": "30s_vectorDistance",
"body": [
"const vectorDistance = (...coords) => {",
" let pointLength = Math.trunc(coords.length / 2);",
" let sum = coords",
" .slice(0, pointLength)",
" .reduce((acc, val, i) => acc + Math.pow(val - coords[pointLength + i], 2), 0);",
" return Math.sqrt(sum);",
"};"
],
"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"
},
"when": {
"prefix": "30s_when",
"body": [