Examples
Read a price calculation in integer cents
Input
function total(cents,qty){return cents*qty;}Expected answer
function total(cents, qty) {
return cents * qty;
}Inspect a retry decision for HTTP 429
Input
if(status===429){retryAfter(30);}Expected answer
if (status === 429) {
retryAfter(30);
}Keep an escaped newline inside a JavaScript string
Input
var forecast="Rain\nSun";show(forecast);Expected answer
var forecast = "Rain\nSun";
show(forecast);Keep URL punctuation inside a quoted string
Input
var url="https://example.org/search?q=caf%C3%A9&limit=5";open(url);Expected answer
var url = "https://example.org/search?q=caf%C3%A9&limit=5";
open(url);Inspect a JSON round-trip without executing it
Input
function copy(value){return JSON.parse(JSON.stringify(value));}Expected answer
function copy(value) {
return JSON.parse(JSON.stringify(value));
}This will not do a perfect job, and the resulting code may not work any more. This operation is designed purely to make obfuscated or minified code more easy to read and understand. Things which will not work properly:For loop formatting Do-While loop formatting Switch/Case indentation Certain bit shift operators