Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!