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

190
Views
Split a string into an array where each string uses single quotes

In JavaScript I am trying to solve this code war problem but every time I test it, the test run fails because my return array is returning this over what's expected

Expected:

'[[14,"a"],[1,"b"],[41,"a"],[1,"c"]]'

instead got:

[[14, 'a'], [1, 'b'], [41, 'a'], [1, 'c']]

I noticed that my str.split is returning this as an array ["a", "a", "a", "a", "a", "a", "a", "a", "a", "a", …]

Basically I realized that if I can return the split str into single quotes it might fix the expected return how can I go about this.

var compress = function(str) {
  let strArr = str.split('')
  let counter = 1
  let rtnArr = []
  console.log(strArr)

  const strMap = strArr.map((val, idx) => {
    if (val === (strArr[idx + 1])) counter += 1
    else {
      rtnArr.push([counter, val])
      counter = 1
    }
  })
  //  console.log(rtnArr)
  return rtnArr
}
about 4 years ago · Juan Pablo Isaza
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!