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

216
Views
¿Cómo crear una función que reciba una cadena "abcbdbd"?

 /** * Let us create a function that receives a string "abcbdbd", * and returns an array like: ["a", "ab", "abc", "abcb", "abcbd", "abcbdb", ...] */ function splitString(str) { const arr = []; for (var i = 0; i < str.length; i++) { arr.push(str[i]); for (var z = 0; z < arr.length; z++) { const joinArr = `${arr[0]}.${arr[z]}`; console.log(joinArr); } } return []; } console.log(splitString("abcdebfkjj"));

cómo añadir . después de cada cadena? He intentado para bucle. Entonces, ¿debería usar map y .join?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Un ejemplo usando map

 const str = "abcbdef"; const array = str.split(""); const output = array.map((_, idx, arr) => arr.slice(0, idx + 1).join(".")); console.log(output);

about 4 years ago · Juan Pablo Isaza Report

0

Cree una matriz a partir de la cadena ( Array.from() ), redúzcala a una matriz, de modo que cada elemento sea el último elemento actual ( acc[acc.length-1] ) en la matriz más él mismo. Para el primer elemento, simplemente agréguelo a la matriz.

 function splitString(str) { return Array.from(str).reduce((acc,cv) => { if (acc[0]) acc.push(acc[acc.length-1]+"."+cv) else acc[0] = cv // if the array is empty, add just the first char return acc },[]) } console.log(splitString("abcdebfkjj"));

about 4 years ago · Juan Pablo Isaza Report

0

Puede crear una matriz de todos los caracteres y agregar el último valor devuelto.

 function splitString(str) { return Array.from( str, (l => v => l += (l && '.') + v)('') ); } console.log(splitString("abcdebfkjj"));

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!