๐งชTDD Challengeยทbeginnerยทโฑ๏ธ 15โ30mยทโญ 100 XP
M-015Build a Reusable Prompt Template
Description
Nebula Corp's team keeps copy-pasting prompts and manually swapping out variables. They need a simple prompt template engine that takes a template string with {{variable}} placeholders and fills them in from a data object. The current function just returns the raw template without any substitution. Make it work so the team can reuse prompts across their app.
Test Cases (3)
Fills simple template
Should replace both placeholders with values
Input:fillTemplate('Hello {{name}}, welcome to {{company}}!', { name: 'Alice', company: 'Nebula' })
Expected:Hello Alice, welcome to Nebula!
Leaves missing variables as-is
Missing keys should leave the placeholder unchanged
Input:fillTemplate('Hello {{name}}, your role is {{role}}', { name: 'Bob' })
Expected:CONTAINS:{{role}}
Builds few-shot prompt
Should format task, examples, and input correctly
Input:buildFewShotPrompt('Classify sentiment', [{ input: 'Great product!', output: 'positive' }, { input: 'Terrible service', output: 'negative' }], 'Not bad')
Expected:CONTAINS_ALL:Task: Classify sentiment,Input: Great product!,Output: positive,Input: Not bad,Output:
Related Lessons
Click Run / Check to validate your solution