Exemplos
Read an integer-cents checkout total
Entrada
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);
}- Indentar string
- Cotações
Auto- Pontos e vírgulas antes de chaves de fechamento
On- Incluir comentários
On
Inspect Fahrenheit conversion and its zero-degree boundary
Entrada
function celsius(f){return(f-32)*5/9;}Expected answer
function celsius(f) {
return (f - 32) * 5 / 9;
}- Indentar string
- Cotações
Auto- Pontos e vírgulas antes de chaves de fechamento
On- Incluir comentários
On
Switch an API message to double-quoted strings
Entrada
function message(name){return 'Hello, '+name+'!';}Expected answer
function message(name) {
return "Hello, " + name + "!";
}- Indentar string
- Cotações
Double- Pontos e vírgulas antes de chaves de fechamento
On- Incluir comentários
On
Keep a note explaining a longitude-latitude pair
Entrada
// 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
]
};- Indentar string
- Cotações
Single- Pontos e vírgulas antes de chaves de fechamento
On- Incluir comentários
On
Remove a stale comment while keeping a leap-year check
Entrada
/* 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)
}- Indentar string
- Cotações
Auto- Pontos e vírgulas antes de chaves de fechamento
Off- Incluir comentários
Off
Parâmetros
| Parâmetro | Valor padrão | Entrada e opções |
|---|---|---|
| Indentar string | "\\t" | Sequências de escape como \n, \r e \t são aceitas |
| Cotações | Automático | Automático, Solteiro, Duplo |
| Pontos e vírgulas antes de chaves de fechamento | true | Ativado ou desativado |
| Incluir comentários | true | Ativado ou desativado |