Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
Compare/classify equal-length strings in a Wordle-like manner?

I'm making a word guessing application (like Wordle).
Let's assume I have a predefined word

let predefinedWord = "apple";

I want to make a function to compare with the predefined word.

const compare = (word) => {
  // compare the guess with the predefined word apple
}

let myGuess = "alley"
const result = compare(myGuess); // compare apple with alley
// return 
// ["Matched", "Included", "Included", "Included", "Not Matched"]

How can I make the function like this?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

If the word length is as short as in wordle, a direct approach works well:

let predefinedWord = "apple";
let predefArr = predefinedWord.split('');


const compare = (predef,word) => {
  return word
         .split('')
         .map( (letter,i) => {
           if (predef[i] === letter) return "Matched";
           if (predef.includes(letter)) return "Included";
           return "Not Matched"
         });
  
}

let myGuess = "alley"
const result = compare(predefArr, myGuess); // compare apple with alley
// return 
// ["Matched", "Included", "Included", "Included", "Not Matched"]

console.log(result)

EDIT: This answers the original question:

let myGuess = "alley"
const result = compare(myGuess); // compare apple with alley
// return 
// ["Matched", "Included", "Included", "Included", "Not Matched"]

How can I make the function like this?

And it is not the behaviour of the game wordle

about 4 years ago · Juan Pablo Isaza Denunciar

0

const compare = (word) => {
  let result = [];
  for(let i=0;i<word.length;i++){
    if(predefinedWord.includes(word[i])){
      result.push(predefinedWord.indexOf(word[i]) === i?"Matched":"Included")
    }else{
      result.push("Not Matched")
    }
  }
  return result;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

function comparisonhint(secret, guess) {
  try {
    const secretArr = secret.split('');
    const guessArr = guess.split('');
    if (secretArr.length !== guessArr.length) {
      throw 'Secret and Guess must be same length.'
    }
    const hintArr = guessArr.map((letter, i) => {
      return secretArr[i] == letter ? '✅' : secretArr.includes(letter) ? '🤏' : '❌';
    });
    return hintArr.join('');
  } catch (err) {
    console.error(err);
    return err;
  }
}

const hint = comparisonhint('words', 'guess');

console.log(hint);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda