Tell us what’s happening:
Hi !
I encountered a problem with the test “Markov”. Why have I the output “rules is not defined”?
I don’t understand what I’m doing wrong.
Thanks in advance
Your code so far
function markov(rules, test) {
const regex = /#.*/gm;
let line = 0, pattern, replacement, terminating = false;
while (line < rules.length) {
if (regex.test(rules[line])) {
line++;
continue;
}
[pattern, replacement] = rules[line].split(' -> ').map(x => x.trim());
if (replacement.charAt(0) == '.') {
terminating = true;
replacement = replacement.substr(1);
}
test = test.replace(pattern, replacement);
if (terminating) break;
line++;
}
return test;
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0
.
Challenge: Execute a Markov algorithm
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/rosetta-code/execute-a-markov-algorithm