Write render(template, data) that fills {{ path }} placeholders with values from data.
A placeholder is a path between {{ and }}: a key, or keys joined by dots, like {{ user.name }}. There may be spaces inside the braces.
Replace each placeholder with the value at its path in data. A missing, null, or undefined value renders as an empty string. Anything else goes through String, so 0 and false show up as 0 and false.
Insert values as plain text, exactly as they are: a value that contains {{ b }} isn't filled in again, and a $& or $1 in a value stays as it is. Leave everything else in the template, including single braces, unchanged.
function render(template, data) {
// your code
}
// render("Hi {{ user.name }}, you have {{count}} messages", { user: { name: "Ada" }, count: 0 });
// // "Hi Ada, you have 0 messages"
// render("{{ a }} and {{ missing }}", { a: "{{ b }} costs $1", b: "x" });
// // "{{ b }} costs $1 and "
Solve it in the editor, with tests
The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…