mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-14 12:47:49 +00:00
Math them all.
This commit is contained in:
@@ -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.
|
* 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`.
|
* @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
||||||
*/
|
*/
|
||||||
function baseInRange(number, start, end) {
|
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
|
export default baseInRange
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import arrayIncludesWith from './arrayIncludesWith.js'
|
|||||||
import arrayMap from './arrayMap.js'
|
import arrayMap from './arrayMap.js'
|
||||||
import cacheHas from './cacheHas.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
|
* The base implementation of methods like `intersection` that accepts an
|
||||||
* array of arrays to inspect.
|
* array of arrays to inspect.
|
||||||
@@ -33,7 +30,7 @@ function baseIntersection(arrays, iteratee, comparator) {
|
|||||||
if (othIndex && iteratee) {
|
if (othIndex && iteratee) {
|
||||||
array = arrayMap(array, (value) => iteratee(value))
|
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))
|
caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
|
||||||
? new SetCache(othIndex && array)
|
? new SetCache(othIndex && array)
|
||||||
: undefined
|
: undefined
|
||||||
|
|||||||
@@ -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
|
* The base implementation of `range` and `rangeRight` which doesn't
|
||||||
* coerce arguments.
|
* coerce arguments.
|
||||||
@@ -15,7 +11,7 @@ const nativeMax = Math.max
|
|||||||
*/
|
*/
|
||||||
function baseRange(start, end, step, fromRight) {
|
function baseRange(start, end, step, fromRight) {
|
||||||
let index = -1
|
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)
|
const result = new Array(length)
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import isSymbol from '../isSymbol.js'
|
|||||||
const MAX_ARRAY_LENGTH = 4294967295
|
const MAX_ARRAY_LENGTH = 4294967295
|
||||||
const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1
|
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`
|
* The base implementation of `sortedIndexBy` and `sortedLastIndexBy`
|
||||||
* which invokes `iteratee` for `value` and each element of `array` to compute
|
* 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) {
|
while (low < high) {
|
||||||
let setLow
|
let setLow
|
||||||
const mid = nativeFloor((low + high) / 2)
|
const mid = Math.floor((low + high) / 2)
|
||||||
const computed = iteratee(array[mid])
|
const computed = iteratee(array[mid])
|
||||||
const othIsDefined = computed !== undefined
|
const othIsDefined = computed !== undefined
|
||||||
const othIsNull = computed === null
|
const othIsNull = computed === null
|
||||||
@@ -58,7 +55,7 @@ function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
|||||||
high = mid
|
high = mid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nativeMin(high, MAX_ARRAY_INDEX)
|
return Math.min(high, MAX_ARRAY_INDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default baseSortedIndexBy
|
export default baseSortedIndexBy
|
||||||
|
|||||||
@@ -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,
|
* Creates an array that is the composition of partially applied arguments,
|
||||||
* placeholders, and provided arguments into a single array of 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 argsIndex = -1
|
||||||
let leftIndex = -1
|
let leftIndex = -1
|
||||||
let rangeLength = nativeMax(argsLength - holdersLength, 0)
|
let rangeLength = Math.max(argsLength - holdersLength, 0)
|
||||||
|
|
||||||
const result = new Array(leftLength + rangeLength)
|
const result = new Array(leftLength + rangeLength)
|
||||||
const isUncurried = !isCurried
|
const isUncurried = !isCurried
|
||||||
|
|||||||
@@ -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
|
* This function is like `composeArgs` except that the arguments composition
|
||||||
* is tailored for `partialRight`.
|
* is tailored for `partialRight`.
|
||||||
@@ -20,7 +17,7 @@ function composeArgsRight(args, partials, holders, isCurried) {
|
|||||||
const argsLength = args.length
|
const argsLength = args.length
|
||||||
const holdersLength = holders.length
|
const holdersLength = holders.length
|
||||||
const rightLength = partials.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 result = new Array(rangeLength + rightLength)
|
||||||
const isUncurried = !isCurried
|
const isUncurried = !isCurried
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ import hasUnicode from './hasUnicode.js'
|
|||||||
import stringSize from './stringSize.js'
|
import stringSize from './stringSize.js'
|
||||||
import stringToArray from './stringToArray.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
|
* Creates the padding for `string` based on `length`. The `chars` string
|
||||||
* is truncated if the number of characters exceeds `length`.
|
* is truncated if the number of characters exceeds `length`.
|
||||||
@@ -24,7 +21,7 @@ function createPadding(length, chars) {
|
|||||||
if (charsLength < 2) {
|
if (charsLength < 2) {
|
||||||
return charsLength ? baseRepeat(chars, length) : chars
|
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)
|
return hasUnicode(chars)
|
||||||
? castSlice(stringToArray(result), 0, length).join('')
|
? castSlice(stringToArray(result), 0, length).join('')
|
||||||
: result.slice(0, length)
|
: result.slice(0, length)
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ const WRAP_CURRY_FLAG = 8
|
|||||||
const WRAP_ARY_FLAG = 128
|
const WRAP_ARY_FLAG = 128
|
||||||
const WRAP_REARG_FLAG = 256
|
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`.
|
* Merges the function metadata of `source` into `data`.
|
||||||
*
|
*
|
||||||
@@ -76,7 +73,7 @@ function mergeData(data, source) {
|
|||||||
}
|
}
|
||||||
// Use source `ary` if it's smaller.
|
// Use source `ary` if it's smaller.
|
||||||
if (srcBitmask & WRAP_ARY_FLAG) {
|
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.
|
// Use source `arity` if one is not provided.
|
||||||
if (data[9] == null) {
|
if (data[9] == null) {
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ import toFinite from './toFinite.js'
|
|||||||
/** Built-in method references without a dependency on `root`. */
|
/** Built-in method references without a dependency on `root`. */
|
||||||
const freeParseFloat = parseFloat
|
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.
|
* 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
|
* 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
|
upper = temp
|
||||||
}
|
}
|
||||||
if (floating || lower % 1 || upper % 1) {
|
if (floating || lower % 1 || upper % 1) {
|
||||||
const rand = nativeRandom()
|
const rand = Math.random()
|
||||||
const randLength = `${ rand }`.length - 1
|
const randLength = `${ rand }`.length - 1
|
||||||
return Math.min(lower + (rand * (upper - lower + freeParseFloat(`1e-${ randLength }`)), upper))
|
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
|
export default random
|
||||||
|
|||||||
10
repeat.js
10
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.
|
* Repeats the given string `n` times.
|
||||||
*
|
*
|
||||||
@@ -25,7 +19,7 @@ const nativeFloor = Math.floor
|
|||||||
*/
|
*/
|
||||||
function repeat(string, n) {
|
function repeat(string, n) {
|
||||||
let result = ''
|
let result = ''
|
||||||
if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
|
if (!string || n < 1 || n > Number.MAX_SAFE_INTEGER) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
// Leverage the exponentiation by squaring algorithm for a faster repeat.
|
// Leverage the exponentiation by squaring algorithm for a faster repeat.
|
||||||
@@ -34,7 +28,7 @@ function repeat(string, n) {
|
|||||||
if (n % 2) {
|
if (n % 2) {
|
||||||
result += string
|
result += string
|
||||||
}
|
}
|
||||||
n = nativeFloor(n / 2)
|
n = Math.floor(n / 2)
|
||||||
if (n) {
|
if (n) {
|
||||||
string += string
|
string += string
|
||||||
}
|
}
|
||||||
|
|||||||
5
unzip.js
5
unzip.js
@@ -3,9 +3,6 @@ import arrayMap from './.internal/arrayMap.js'
|
|||||||
import baseProperty from './.internal/baseProperty.js'
|
import baseProperty from './.internal/baseProperty.js'
|
||||||
import isArrayLikeObject from './isArrayLikeObject.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
|
* 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
|
* elements and creates an array regrouping the elements to their pre-zip
|
||||||
@@ -31,7 +28,7 @@ function unzip(array) {
|
|||||||
let length = 0
|
let length = 0
|
||||||
array = arrayFilter(array, (group) => {
|
array = arrayFilter(array, (group) => {
|
||||||
if (isArrayLikeObject(group)) {
|
if (isArrayLikeObject(group)) {
|
||||||
length = nativeMax(group.length, length)
|
length = Math.max(group.length, length)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user