Daily Challenge: Word Guesser

Based on the instructions for today’s Daily Challenge, it seems like the expected result for Test #4:

console.log(compare("JAVASCRIPT", "TYPESCRIPT"));

should be “1010222200”, not “0000222222”.

Am I missing something here? All of the other tests pass as expected.

This seems to be covered by the instructions:

  • Each letter in the secret word can be used at most once.
  • Exact matches ("2") are assigned first, then partial matches ("1") are assigned from left to right for remaining letters.
  • If a letter occurs multiple times in the guess, it can only match as many times as it appears in the secret word.

Could you explain your reasoning?

Here’s my reasoning, working from left to right as explained in the instructions:

// t is in javascript but it’s not in the right place : 1
// y is not in javascript: 0
// p is in javascript but it’s not in the right place: 1
// e is not in javascript: 0
// s is in javascript and it’s in the right place: 2
// c is in javascript and it’s in the right place: 2
// r is in javascript and it’s in the right place: 2
// i is in javascript and it’s in the right place: 2
// p is in javascript but the one p in that word has already been used: 0
// t is in javascript but the one t in that word has already been used: 0

try again but following " Exact matches ("2" ) are assigned first,"

1 Like

Thanks. It looks like that’s what I was missing.