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

107
Vistas
La función spinWords no puede elegir una función adecuada para cambiar el texto

hola, soy un desarrollador web junior, lo siento por mi pregunta tonta, le doy un texto a la función spinWords , si el texto incluye palabras prohibidas, debería devolver la función " ifWordExistsInList() " y si no devuelve " ifWordNotExistInList( ) ", pero la función spinwords solo devuelve uno de ellos y no puede decidir cuál es mejor, ¿puede solucionarlo? ( otras funciones funcionan bien, solo spinWords es el problema ).

 const _SRC_ = { //list of sentences that includes forbidden words ( just for test ) listOfTries: [ "Welcome", "Hey fellow warriors", "This is a test", "This is another test", "You are almost to the last test", "Just kidding there is still one more", "Seriously this is the last one", ], //list of forbidden words forbiddenWords: [ "Welcome", "fellow", "warriors", "another", "almost", "kidding", "there", "still", "Seriously", "sentence", "rrxqsqpw", ], }; //this function reverses the forbidden words only ex: hey fellow warriors => hey wollef sroirraw function ifWordExistsInList(value) { const reverse = (item) => { return [...item].reverse().join(""); }; let collection = value; _SRC_.forbiddenWords.forEach((word) => { const reg = new RegExp(word, "gi"); collection = collection.replace(reg, reverse(word)); }); return collection; } //this function reveses all the words ex: hello world => olleh dlrow function ifWordNotExistInList(string) { const makeArray = string.split(" "); // [ hello , world ] const reversed = []; makeArray.forEach((item) => { const each = [...item]; // [ h,e,l,l,o ] const word = each.reverse().join(""); reversed.push(word); }); return reversed.join(" "); } /* in this function we check text to decide which fucntion is proper if text is nonsense then go with function 'ifWordNotExistInList()' and if text has forbidden words go with 'ifWordExistsInList()' */ function spinWords(text) { // this function is the problem , and doesn't work the way that it should for (var item in _SRC_.forbiddenWords) { if (text.includes(item)) { return ifWordExistsInList(text); } else { return ifWordNotExistInList(text); } } } //Here i check different sentences //nonsense text test var test = "ksdf skdjfh"; //sentences that includes forbidden words - i loop through them console.log(`${test} => `, spinWords(test), "\n---------------------------"); _SRC_.listOfTries.forEach((item) => { console.log("-- ", spinWords(item)); });
about 4 years ago · Juan Pablo Isaza
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