Modify the logic to make the code more intuitive (#3472)

This commit is contained in:
JiaWen Peng
2017-11-04 07:08:28 -05:00
committed by John-David Dalton
parent 7c006f7445
commit 30d305da0f

View File

@@ -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)
} }
} }