Update functional-tools.js

This commit is contained in:
Andros Fenollosa 2022-02-03 21:36:41 +01:00 committed by GitHub
parent 0505745d4a
commit c5811018c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,8 @@ function updateJSON(key, newValue, json) {
}, {}); }, {});
} }
export default updateJSON
/** /**
* Returns an array with a sequence. * Returns an array with a sequence.
* *
@ -41,3 +43,76 @@ function range(start, stop=undefined, step=1) {
const stopArray = stop === undefined ? start : stop; const stopArray = stop === undefined ? start : stop;
return Array.from({ length: (stopArray - startArray) / step + 1}, (_, i) => startArray + (i * step)); return Array.from({ length: (stopArray - startArray) / step + 1}, (_, i) => startArray + (i * step));
} }
export default range
/**
* Creates a duplicate-free version of an array.
*
* @category Array
* @param {Array} array The array to inspect.
* @returns {Array} Returns the new duplicate free array.
* @example
*
* uniq([2, 1, 2, 2])
* // => [2, 1]
*/
function uniq(array) {
return (array != null && array.length)
? Array.from(new Set(array))
: [];
}
export default uniq
/**
* Increase the value of a `number`.
*
* @param {number} number The number to increase.
* @param {number} number Increase.
* @return {number} Returns the decrease.
* @example
*
* inc(4)
* // => 5
*
* inc(5, 3)
* // => 8
*
* dec(7.3)
* // => 8.3
*
*/
function inc(number, increase=1) {
return number - increase;
}
export default dec
/**
* Decrease the value of a `number`.
*
* @since 4.17.15
* @category Math
* @param {number} number The number to decrease.
* @param {number} number Decrease.
* @return {number} Returns the decrease.
* @example
*
* dec(4)
* // => 3
*
* dec(5, 3)
* // => 2
*
* dec(7.3)
* // => 6.3
*
* dec("foo")
* // => false
*/
function dec(number, decrease=1) {
return number - decrease;
}
export default dec