mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +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) {
|
function createMathOperation(operator, defaultValue) {
|
||||||
return (value, other) => {
|
return (value, other) => {
|
||||||
let result
|
|
||||||
if (value === undefined && other === undefined) {
|
if (value === undefined && other === undefined) {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
if (value !== undefined) {
|
if (value != undefined && other === undefined){
|
||||||
result = value
|
return value
|
||||||
}
|
}
|
||||||
if (other !== undefined) {
|
if (other !== undefined && value === undefined) {
|
||||||
if (result === undefined) {
|
return other
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
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