_.lte(value, other)

164

_.lte(value, other)
_.lte判断value是否小于等于other

参数

value (*): 需要比较的值
other (*): 需要比较的另外一个值

返回值

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

例子

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

源代码

/**
 * Checks if `value` is less 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 less than or equal to
 *  `other`, else `false`.
 * @see gt, gte, lt
 * @example
 *
 * lte(1, 3)
 * // => true
 *
 * lte(3, 3)
 * // => true
 *
 * lte(3, 1)
 * // => false
 */
//判断value是否小于等于other
function lte(value, other) {
  if (!(typeof value == 'string' && typeof other == 'string')) {
    //如果value和other不同时是字符串,转换成number对象再比较
    value = +value
    other = +other
  }
  return value <= other
}

export default lte

 

posted @ 2019-01-10 19:58  hahazexia  阅读(186)  评论(0)    收藏  举报