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

192
Vistas
How to count backwards

Hey guys im developing something and I need to fix this please give me some feedback on how to improve this. (how to make it cleaner, easier to read , etc). Here's the code!

function wordFliper(word) {
    let wordOutput = "";
    let reverseIndex = word.length - 1;
    for (let index = reverseIndex; index >= 0; index--) {
      let storage = word[index];
      wordOutput = wordOutput + storage;
    }
    return wordOutput;
  }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use JS array functions like reduce(),split(),reverse(), etc. You can write the code in following ways:

  1. function wordFlipper(word) {
        return(word.split('').reverse().join(''));
    }
    
  2. function wordFlipper(word) {
        return(word.split('').reduce((a,c)=>c+a));
    }
    

Please go through the links for clarity on the functions used above:

  • split() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
  • join() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
  • reverse() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
  • reduce() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
about 4 years ago · Juan Pablo Isaza Denunciar

0

I would remove some variables (variables that are used once in loop and then assigned to a function variable) to reduce code and rename one like this:

/// <summary>Function to flip words backwards</summary>
/// <param name="word" type="string">Word to be flipped</param>
/// <returns type="string">Word flipped</returns>

function wordFlipper(word) {
    let flippedWord = "";
    for (let i = word.length - 1; i >= 0; i--) {
      flippedWord += word[i];
    }
    return flippedWord;
}

Also IMHO use i variable instead of index (for loop incrementer)

And Also get used to commenting your code, to know what is for the functions you're writing

I hope you helped to keep your code clean for further programming and happy coding!

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