描述
這個min()方法接受一組數字並返回給定數字中的最小值。在不傳遞參數的情況下調用此方法時,它返回 +Infinity。
用法
下麵給出的是min()JavaScript 的方法。我們可以在 CoffeeScript 代碼中使用相同的方法。
Math.min ( x )
示例
下麵的例子演示了min()CoffeeScript 中的方法。將此代碼保存在具有名稱的文件中math_min.coffee。
value = Math.min 10, 20, -1, 100
console.log "The min value among (10, 20, -1, 100) is:" + value
value = Math.min -1, -3, -40
console.log "The min value among (-1, -3, -40) is:" + value
value = Math.min 0, -1
console.log "The min value among (0, -1) is:" + value
打開command prompt並編譯 .coffee 文件,如下所示。
c:\> coffee -c math_min.coffee
在編譯時,它會為您提供以下 JavaScript。
// Generated by CoffeeScript 1.10.0
(function() {
var value;
value = Math.min(10, 20, -1, 100);
console.log("The min value among (10, 20, -1, 100) is:" + value);
value = Math.min(-1, -3, -40);
console.log("The min value among (-1, -3, -40) is:" + value);
value = Math.min(0, -1);
console.log("The min value among (0, -1) is:" + value);
}).call(this);
現在,打開command prompt再次運行 CoffeeScript 文件,如下所示。
c:\> coffee math_max.coffee
在執行時,CoffeeScript 文件產生以下輸出。
The min value among (10, 20, -1, 100) is:-1 The min value among (-1, -3, -40) is:-40 The min value among (0, -1) is:-1
相關用法
- CoffeeScript Math max()用法及代碼示例
- CoffeeScript Math pow()用法及代碼示例
- CoffeeScript Math floor()用法及代碼示例
- CoffeeScript Math cos()用法及代碼示例
- CoffeeScript Math sqrt()用法及代碼示例
- CoffeeScript Math atan2()用法及代碼示例
- CoffeeScript Math tan()用法及代碼示例
- CoffeeScript Math atan()用法及代碼示例
- CoffeeScript Math log()用法及代碼示例
- CoffeeScript Math acos()用法及代碼示例
- CoffeeScript Math asin()用法及代碼示例
- CoffeeScript Math sin()用法及代碼示例
- CoffeeScript Math exp()用法及代碼示例
- CoffeeScript Math round()用法及代碼示例
- CoffeeScript Math random()用法及代碼示例
- CoffeeScript Math ceil()用法及代碼示例
- CoffeeScript String slice()用法及代碼示例
- CoffeeScript String toUpperCase()用法及代碼示例
- CoffeeScript Date setHours()用法及代碼示例
- CoffeeScript Date setUTCFullYear()用法及代碼示例
注:本文由純淨天空篩選整理自 CoffeeScript Math - min()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。