mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Modify the logic to make the code more intuitive (#3472)
This commit is contained in:
committed by
John-David Dalton
parent
7c006f7445
commit
30d305da0f
@@ -11,27 +11,24 @@ import baseToString from './baseToString.js'
|
||||
*/
|
||||
function createMathOperation(operator, defaultValue) {
|
||||
return (value, other) => {
|
||||
let result
|
||||
if (value === undefined && other === undefined) {
|
||||
return defaultValue
|
||||
}
|
||||
if (value !== undefined) {
|
||||
result = value
|
||||
if (value != undefined && other === undefined){
|
||||
return value
|
||||
}
|
||||
if (other !== undefined) {
|
||||
if (result === undefined) {
|
||||
return other
|
||||
}
|
||||
if (typeof value == 'string' || typeof other == 'string') {
|
||||
value = baseToString(value)
|
||||
other = baseToString(other)
|
||||
} else {
|
||||
value = baseToNumber(value)
|
||||
other = baseToNumber(other)
|
||||
}
|
||||
result = operator(value, other)
|
||||
if (other !== undefined && value === undefined) {
|
||||
return other
|
||||
}
|
||||
return result
|
||||
if (typeof value == 'string' || typeof other == 'string') {
|
||||
value = baseToString(value)
|
||||
other = baseToString(other)
|
||||
}
|
||||
else {
|
||||
value = baseToNumber(value)
|
||||
other = baseToNumber(other)
|
||||
}
|
||||
return operator(value, other)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user