Esempi
Read an integer-cents checkout total
Input
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);
}- Indenta stringa
- Citazioni
Auto- Punti e virgola prima delle parentesi graffe di chiusura
On- Includi commenti
On
Inspect Fahrenheit conversion and its zero-degree boundary
Input
function celsius(f){return(f-32)*5/9;}Expected answer
function celsius(f) {
return (f - 32) * 5 / 9;
}- Indenta stringa
- Citazioni
Auto- Punti e virgola prima delle parentesi graffe di chiusura
On- Includi commenti
On
Switch an API message to double-quoted strings
Input
function message(name){return 'Hello, '+name+'!';}Expected answer
function message(name) {
return "Hello, " + name + "!";
}- Indenta stringa
- Citazioni
Double- Punti e virgola prima delle parentesi graffe di chiusura
On- Includi commenti
On
Keep a note explaining a longitude-latitude pair
Input
// 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
]
};- Indenta stringa
- Citazioni
Single- Punti e virgola prima delle parentesi graffe di chiusura
On- Includi commenti
On
Remove a stale comment while keeping a leap-year check
Input
/* 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)
}- Indenta stringa
- Citazioni
Auto- Punti e virgola prima delle parentesi graffe di chiusura
Off- Includi commenti
Off
Parametri
| Parametro | Valore predefinito | Input e opzioni |
|---|---|---|
| Indenta stringa | "\\t" | Sono supportate sequenze di escape come \n, \r e \t |
| Citazioni | Automatico | Automatico, Singolo, Doppio |
| Punti e virgola prima delle parentesi graffe di chiusura | true | Attivo o disattivo |
| Includi commenti | true | Attivo o disattivo |