// A strict robot: it reads each step and complains about every word it cannot measure.
// (You will understand every line of this program by Chapter 9. For now, run it and read what it says.)
const vague = ["some", "a bit", "a little", "enough", "until ready", "a cup", "hot"];
const vagueSteps = [
"Put some water in the kettle",
"Boil it until ready",
"Put a tea bag in a cup",
"Add a bit of sugar",
];
const preciseSteps = [
"Fill the kettle to the 0.5 litre line",
"Press the switch and wait until it jumps up by itself",
"Put one tea bag in the white mug",
"Add 1 teaspoon of sugar and stir 5 times",
];
function check(title, steps) {
console.log(`== ${title}`);
let problems = 0;
steps.forEach((step, i) => {
const found = vague.filter((word) => step.includes(word));
if (found.length > 0) {
problems++;
console.log(`Step ${i + 1}: "${step}" -> I do not understand: ${found.join(", ")}`);
} else {
console.log(`Step ${i + 1}: OK`);
}
});
console.log(problems === 0 ? "I can make this tea!" : `Unclear steps: ${problems}`);
console.log("");
}
check("A friend's first try", vagueSteps);
check("Our precise steps", preciseSteps);
Recorded output$ node robot.js
== A friend's first try
Step 1: "Put some water in the kettle" -> I do not understand: some
Step 2: "Boil it until ready" -> I do not understand: until ready
Step 3: "Put a tea bag in a cup" -> I do not understand: a cup
Step 4: "Add a bit of sugar" -> I do not understand: a bit
Unclear steps: 4
== Our precise steps
Step 1: OK
Step 2: OK
Step 3: OK
Step 4: OK
I can make this tea!