From 2538a5657794e3327126c53e3447144e8e3705c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipi=C5=84ski?= Date: Tue, 4 Apr 2017 22:38:50 +0200 Subject: [PATCH] Math them all. --- .internal/baseInRange.js | 6 +----- .internal/baseIntersection.js | 5 +---- .internal/baseRange.js | 6 +----- .internal/baseSortedIndexBy.js | 7 ++----- .internal/composeArgs.js | 5 +---- .internal/composeArgsRight.js | 5 +---- .internal/createPadding.js | 5 +---- .internal/mergeData.js | 5 +---- random.js | 7 ++----- repeat.js | 10 ++-------- unzip.js | 5 +---- 11 files changed, 14 insertions(+), 52 deletions(-) diff --git a/.internal/baseInRange.js b/.internal/baseInRange.js index 0d266ea53..607bc661b 100644 --- a/.internal/baseInRange.js +++ b/.internal/baseInRange.js @@ -1,7 +1,3 @@ -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max -const nativeMin = Math.min - /** * The base implementation of `inRange` which doesn't coerce arguments. * @@ -12,7 +8,7 @@ const nativeMin = Math.min * @returns {boolean} Returns `true` if `number` is in the range, else `false`. */ function baseInRange(number, start, end) { - return number >= nativeMin(start, end) && number < nativeMax(start, end) + return number >= Math.min(start, end) && number < Math.max(start, end) } export default baseInRange diff --git a/.internal/baseIntersection.js b/.internal/baseIntersection.js index 631530761..5f0717709 100644 --- a/.internal/baseIntersection.js +++ b/.internal/baseIntersection.js @@ -4,9 +4,6 @@ import arrayIncludesWith from './arrayIncludesWith.js' import arrayMap from './arrayMap.js' import cacheHas from './cacheHas.js' -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMin = Math.min - /** * The base implementation of methods like `intersection` that accepts an * array of arrays to inspect. @@ -33,7 +30,7 @@ function baseIntersection(arrays, iteratee, comparator) { if (othIndex && iteratee) { array = arrayMap(array, (value) => iteratee(value)) } - maxLength = nativeMin(array.length, maxLength) + maxLength = Math.min(array.length, maxLength) caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) ? new SetCache(othIndex && array) : undefined diff --git a/.internal/baseRange.js b/.internal/baseRange.js index 5dfe07b91..94491b486 100644 --- a/.internal/baseRange.js +++ b/.internal/baseRange.js @@ -1,7 +1,3 @@ -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeCeil = Math.ceil -const nativeMax = Math.max - /** * The base implementation of `range` and `rangeRight` which doesn't * coerce arguments. @@ -15,7 +11,7 @@ const nativeMax = Math.max */ function baseRange(start, end, step, fromRight) { let index = -1 - let length = nativeMax(nativeCeil((end - start) / (step || 1)), 0) + let length = Math.max(Math.ceil((end - start) / (step || 1)), 0) const result = new Array(length) while (length--) { diff --git a/.internal/baseSortedIndexBy.js b/.internal/baseSortedIndexBy.js index 0e0ea7bcc..fdc5c17bb 100644 --- a/.internal/baseSortedIndexBy.js +++ b/.internal/baseSortedIndexBy.js @@ -4,9 +4,6 @@ import isSymbol from '../isSymbol.js' const MAX_ARRAY_LENGTH = 4294967295 const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1 -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeFloor = Math.floor, nativeMin = Math.min - /** * The base implementation of `sortedIndexBy` and `sortedLastIndexBy` * which invokes `iteratee` for `value` and each element of `array` to compute @@ -32,7 +29,7 @@ function baseSortedIndexBy(array, value, iteratee, retHighest) { while (low < high) { let setLow - const mid = nativeFloor((low + high) / 2) + const mid = Math.floor((low + high) / 2) const computed = iteratee(array[mid]) const othIsDefined = computed !== undefined const othIsNull = computed === null @@ -58,7 +55,7 @@ function baseSortedIndexBy(array, value, iteratee, retHighest) { high = mid } } - return nativeMin(high, MAX_ARRAY_INDEX) + return Math.min(high, MAX_ARRAY_INDEX) } export default baseSortedIndexBy diff --git a/.internal/composeArgs.js b/.internal/composeArgs.js index bc812d87a..1b0406e51 100644 --- a/.internal/composeArgs.js +++ b/.internal/composeArgs.js @@ -1,6 +1,3 @@ -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max - /** * Creates an array that is the composition of partially applied arguments, * placeholders, and provided arguments into a single array of arguments. @@ -19,7 +16,7 @@ function composeArgs(args, partials, holders, isCurried) { let argsIndex = -1 let leftIndex = -1 - let rangeLength = nativeMax(argsLength - holdersLength, 0) + let rangeLength = Math.max(argsLength - holdersLength, 0) const result = new Array(leftLength + rangeLength) const isUncurried = !isCurried diff --git a/.internal/composeArgsRight.js b/.internal/composeArgsRight.js index 4c6c2090b..7e037c198 100644 --- a/.internal/composeArgsRight.js +++ b/.internal/composeArgsRight.js @@ -1,6 +1,3 @@ -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max - /** * This function is like `composeArgs` except that the arguments composition * is tailored for `partialRight`. @@ -20,7 +17,7 @@ function composeArgsRight(args, partials, holders, isCurried) { const argsLength = args.length const holdersLength = holders.length const rightLength = partials.length - const rangeLength = nativeMax(argsLength - holdersLength, 0) + const rangeLength = Math.max(argsLength - holdersLength, 0) const result = new Array(rangeLength + rightLength) const isUncurried = !isCurried diff --git a/.internal/createPadding.js b/.internal/createPadding.js index 3579cc2c2..ef7556de5 100644 --- a/.internal/createPadding.js +++ b/.internal/createPadding.js @@ -5,9 +5,6 @@ import hasUnicode from './hasUnicode.js' import stringSize from './stringSize.js' import stringToArray from './stringToArray.js' -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeCeil = Math.ceil - /** * Creates the padding for `string` based on `length`. The `chars` string * is truncated if the number of characters exceeds `length`. @@ -24,7 +21,7 @@ function createPadding(length, chars) { if (charsLength < 2) { return charsLength ? baseRepeat(chars, length) : chars } - const result = baseRepeat(chars, nativeCeil(length / stringSize(chars))) + const result = baseRepeat(chars, Math.ceil(length / stringSize(chars))) return hasUnicode(chars) ? castSlice(stringToArray(result), 0, length).join('') : result.slice(0, length) diff --git a/.internal/mergeData.js b/.internal/mergeData.js index f0136dfc0..506d1662b 100644 --- a/.internal/mergeData.js +++ b/.internal/mergeData.js @@ -13,9 +13,6 @@ const WRAP_CURRY_FLAG = 8 const WRAP_ARY_FLAG = 128 const WRAP_REARG_FLAG = 256 -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMin = Math.min - /** * Merges the function metadata of `source` into `data`. * @@ -76,7 +73,7 @@ function mergeData(data, source) { } // Use source `ary` if it's smaller. if (srcBitmask & WRAP_ARY_FLAG) { - data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]) + data[8] = data[8] == null ? source[8] : Math.min(data[8], source[8]) } // Use source `arity` if one is not provided. if (data[9] == null) { diff --git a/random.js b/random.js index a10a1b475..c297285e3 100644 --- a/random.js +++ b/random.js @@ -3,9 +3,6 @@ import toFinite from './toFinite.js' /** Built-in method references without a dependency on `root`. */ const freeParseFloat = parseFloat -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeRandom = Math.random - /** * Produces a random number between the inclusive `lower` and `upper` bounds. * If only one argument is provided a number between `0` and the given number @@ -66,11 +63,11 @@ function random(lower, upper, floating) { upper = temp } if (floating || lower % 1 || upper % 1) { - const rand = nativeRandom() + const rand = Math.random() const randLength = `${ rand }`.length - 1 return Math.min(lower + (rand * (upper - lower + freeParseFloat(`1e-${ randLength }`)), upper)) } - return lower + Math.floor(nativeRandom() * (upper - lower + 1)) + return lower + Math.floor(Math.random() * (upper - lower + 1)) } export default random diff --git a/repeat.js b/repeat.js index b778750b0..89d8403da 100644 --- a/repeat.js +++ b/repeat.js @@ -1,9 +1,3 @@ -/* Used as references for the maximum safe integer in JavaScript Math.pow(2, 53) - 1 */ -const MAX_SAFE_INTEGER = 9007199254740991 - -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeFloor = Math.floor - /** * Repeats the given string `n` times. * @@ -25,7 +19,7 @@ const nativeFloor = Math.floor */ function repeat(string, n) { let result = '' - if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + if (!string || n < 1 || n > Number.MAX_SAFE_INTEGER) { return result } // Leverage the exponentiation by squaring algorithm for a faster repeat. @@ -34,7 +28,7 @@ function repeat(string, n) { if (n % 2) { result += string } - n = nativeFloor(n / 2) + n = Math.floor(n / 2) if (n) { string += string } diff --git a/unzip.js b/unzip.js index 3b96b3015..34d5058ca 100644 --- a/unzip.js +++ b/unzip.js @@ -3,9 +3,6 @@ import arrayMap from './.internal/arrayMap.js' import baseProperty from './.internal/baseProperty.js' import isArrayLikeObject from './isArrayLikeObject.js' -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMax = Math.max - /** * This method is like `zip` except that it accepts an array of grouped * elements and creates an array regrouping the elements to their pre-zip @@ -31,7 +28,7 @@ function unzip(array) { let length = 0 array = arrayFilter(array, (group) => { if (isArrayLikeObject(group)) { - length = nativeMax(group.length, length) + length = Math.max(group.length, length) return true } })