範例
Read an integer-cents checkout total
輸入
function totalCents(items){return items.reduce(function(sum,item){return sum+item.cents*item.quantity;},0);}Expected answer
function totalCents(items) {
return items.reduce(function (sum, item) {
return sum + item.cents * item.quantity;
}, 0);
}- 縮進字串
- 引號
Auto- 在右花括號前保留分號
On- 包含注释
On
Inspect Fahrenheit conversion and its zero-degree boundary
輸入
function celsius(f){return(f-32)*5/9;}Expected answer
function celsius(f) {
return (f - 32) * 5 / 9;
}- 縮進字串
- 引號
Auto- 在右花括號前保留分號
On- 包含注释
On
Switch an API message to double-quoted strings
輸入
function message(name){return 'Hello, '+name+'!';}Expected answer
function message(name) {
return "Hello, " + name + "!";
}- 縮進字串
- 引號
Double- 在右花括號前保留分號
On- 包含注释
On
Keep a note explaining a longitude-latitude pair
輸入
// GeoJSON positions use longitude before latitude
var point={type:"Point",coordinates:[100,0]};Expected answer
// GeoJSON positions use longitude before latitude
var point = {
type: 'Point',
coordinates: [
100,
0
]
};- 縮進字串
- 引號
Single- 在右花括號前保留分號
On- 包含注释
On
Remove a stale comment while keeping a leap-year check
輸入
/* old debug note */function isLeap(y){return y%4===0&&(y%100!==0||y%400===0);}Expected answer
function isLeap(y) {
return y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0)
}- 縮進字串
- 引號
Auto- 在右花括號前保留分號
Off- 包含注释
Off
参數
| 参數 | 默認值 | 輸入與選項 |
|---|---|---|
| 縮進字串 | "\\t" | 支持 \n、\r 和 \t 等跳脫序列 |
| 引號 | 自动 | 自动, Single, Double |
| 在右花括號前保留分號 | true | 開啟或关閉 |
| 包含注释 | true | 開啟或关閉 |