_.gte(value, other)

125

_.gte(value, other)
_.gte检查value是否大于等于other
如果value大于等于other,返回true,否则false

参数

value (*): 需要比较的值
other (*): 需要与value比较的值

返回值

(boolean): 如果value大于等于other,返回true,否则false

例子

_.gte(3, 1);
// => true
 
_.gte(3, 3);
// => true
 
_.gte(1, 3);
// => false

源代码

/**
 * Checks if `value` is greater than or equal to `other`.
 *
 * @since 3.9.0
 * @category Lang
 * @param {*} value The value to compare.
 * @param {*} other The other value to compare.
 * @returns {boolean} Returns `true` if `value` is greater than or equal to
 *  `other`, else `false`.
 * @see gt, lt, lte
 * @example
 *
 * gte(3, 1)
 * // => true
 *
 * gte(3, 3)
 * // => true
 *
 * gte(1, 3)
 * // => false
 */
//检查value是否大于等于other
//如果value大于等于other,返回true,否则false
function gte(value, other) {
  if (!(typeof value == 'string' && typeof other == 'string')) {
    //如果value和other不同时是string类型,转换成number
    value = +value
    other = +other
  }
  return value >= other//返回比较结果
}

export default gte

 

posted @ 2018-12-17 19:02  hahazexia  阅读(434)  评论(0)    收藏  举报