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

194
Views
Código de condensación que compara si una cadena se puede organizar para crear otra cadena

El desafío a resolver fue escribir una función que tome dos cadenas como entradas y si la primera cadena se puede reorganizar para crear la segunda cadena, devuelva la cadena "verdadera". Si no, devuelve "falso". Pude resolverlo, pero mi solución es fornida y no exactamente elocuente. Me gustaría consejos/trucos para condensar el código que escribí.

 //to solve, create (2) objects with the values as the # of appearances of chars // in the (2) strings const countStr1 = {}; const countStr2 = {}; for(let chr of str1) { if (countStr1[chr]) { countStr1[chr]++; } else{ countStr1[chr] = 1; } } for(let chr2 of str2){ if(countStr2[chr2]){ countStr2[chr2]++; } else{ countStr2[chr2] = 1; } } // console.log(countStr1); // console.log(countStr2); // create (2) arrays of keys: const keys1 = Object.keys(countStr1); const keys2 = Object.keys(countStr2); //console.log(keys1.length); //console.log(keys2.length); if (keys2.length > keys1.length){ return "false"; } for (let key of keys2) { // console.log(countStr1[key]); if (countStr1[key] < countStr2[key]){ return "false"; } return "true"; } } // keep this function call here console.log(StringScramble("cdoer","coder"));```
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!