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

184
Vistas
Counting characters inside words using .map

I'm having trouble with getting to the right answer, I'm currently in a course and I'm trying to make a sentance string that I input at the end (at console.log) count the characters for every word that I have, which means, if the sentence is " hey I'm mikey" then it will show [3, 2, 5] this is my code:

const IsstringArray = (StringsArray) => {
  return StringsArray.map(stringarraysplit => {
    stringarraysplit2 = stringarraysplit.split(" ")
    return stringarraysplit2.length
  })
}
console.log(IsstringArray(["hey my name is miki hey"]))

it shows the number of words, but I need the number of characters in those words.

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

0

You can combine Array#map(), String#trim() and String#split()

Code:

const caractersByArray = a =>
  a.map(s =>
    s
      .trim()
      .split(' ')
      .map(s => s.length)
  )

const result = caractersByArray([
  "hey my name is miki hey", 
  " hey I'm mikey"
])

console.log(result)

about 4 years ago · Juan Pablo Isaza Denunciar

0

try this

const IsstringArray = (StringsArray) => {
    const stringarraysplit = StringsArray.split(" ")
    return stringarraysplit.map(stringarraysplit => { 
        return stringarraysplit.length;})
}  

console.log(IsstringArray("hey my name is miki hey"))    
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