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

265
Vistas
How to make abbreviations using a function?

Here is my code, but it does not work.

function makeAbbr(words) {
  var text = '';
  
  words.split(' ');
  
  for (i = 0; i < words.length; i++) {
    text += words[i].substr(0, 1)
  }
  
  return text
}

console.log(makeAbbr('java script'))

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

0

The following should work:

function makeAbbr(someStr) {
  const words = someStr.split(" ");
  let abbr = "";
  for (const word of words) {
    abbr += word.substring(0,1);
  }
  return abbr;
}
makeAbbr("I love JavaScript!"); // IlJ

.split(...) does not mutate the string (and convert it to an array), but returns the array. Therefore, you have to assign the result to a variable.

about 4 years ago · Juan Pablo Isaza Denunciar

0

/**

 * @param {string} words

 *

 * @returns {string}

 */

function makeAbbr(words) {

  let wor = words.split(" ");

  let abbreviation = "";

  for (const word of wor) {

    

  abbreviation += word[0].substring();;

  }

  return abbreviation.toUpperCase();

}

about 4 years ago · Ihor Moskovenko 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