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

147
Views
construir una matriz basada en un texto con delimitador de caracteres

Tengo dificultades para crear una función genérica donde una entrada sería una cadena que contiene un volumen de texto grande o pequeño y la salida es una matriz y tengo muchos problemas con esta complejidad, pero cada posición de la matriz debe contener 125 caracteres como máximo y no puede tener una palabra rota, por ejemplo, si hay alguna palabra final con la que se debe pasar 125 caracteres a la siguiente posición de la matriz.

Ejemplo:

Valor de entrada: `var text =" Lorem Ipsum is simply a text simulation of the printing and printing industry, and has been in use since the 16th century, when an unknown printer took a tray of typefaces and shuffled them together to make a type model book Lorem Ipsum survived not only five centuries but also the leap into desktop publishing, remaining essentially unchanged It became popular in the 1960s when Letraset launched decals containing passages of Lorem Ipsum, and more recently when is now integrated with desktop editing software like Aldus PageMaker." `

Valor de salida incorrecto: `[ "Lorem Ipsum is simply a text simulation of the printing and printing industry, and it has been in use since the century," "XVI, when a printer discovered a type tray and shuffled them together to make a typeface template book."] `

Tenga en cuenta que la posición 0 de la matriz ha pasado de 125 debido a la palabra "siglo".

Valor de salida correcto: `[" Lorem Ipsum is simply a text simulation of the printing and printing industry, and has been in use since the "," 16th century, when an unknown printer took a tray of typefaces and shuffled them to make a book of models of "," types. Lorem Ipsum survived not only five centuries, but also the leap into desktop publishing, remaining ", ...]`

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

0

Puede usar la expresión regular .{1,125}\b que busca con avidez entre 1 y 125 caracteres seguidos de un límite de palabra:

 const regex = /.{1,125}\b/g; var text =" Lorem Ipsum is simply a text simulation of the printing and printing industry, and has been in use since the 16th century, when an unknown printer took a tray of typefaces and shuffled them together to make a type model book Lorem Ipsum survived not only five centuries but also the leap into desktop publishing, remaining essentially unchanged It became popular in the 1960s when Letraset launched decals containing passages of Lorem Ipsum, and more recently when is now integrated with desktop editing software like Aldus PageMaker."; console.log(text.match(regex));

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!