Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda