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

103
Vistas
Slice returns full string rather than first num characters

The string is not being sliced. The full string is being returned, rather than just the first num characters.

function truncateString(str, num) {
      if (str.length > num) {
        str.slice(0,num)
        return str
      } else {
        return str
      }
}

console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8))

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

0

You need to return the result of the slice method:

function truncateString(str, num) {
      if (str.length > num) {
        return str.slice(0,num)
      } else {
        return str
      }
}

console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8))

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