Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
Summarize the text and stick all the letters together

I have a text and want to summarize it , i want change this array :

Array 1

[
  'CALX',  '11.10',  '21',
  '01',    '08',     'EGLD',
  'USDT',  'LDFDFC', 'ZONE',
  '238.5', '233',    'LEVERAGE',
  '3',     'X',      'TARGET',
  '1',     '243.9',  'TARGET',
  '2',     '248',    'TARGET',
  '3',     '254',    'TARGET',
  '4',     '260',    'H',
  'GD',    'S',      'AFCA'
]

to this : Array 2

[
  'CALX',  '11.10',  '21',
  '01',    '08',     'EGLDUSDTLDFDFCZONE',
  '238.5', '233',    'LEVERAGE',
  '3',     'XTARGET',      
  '1',     '243.9',  'TARGET',
  '2',     '248',    'TARGET',
  '3',     '254',    'TARGET',
  '4',     '260',    'HGDSAFCA',
]

as you can see , I want all the letters to stick together until they reach a number,and each number should be in an element of the array

This is the code that can be used to convert text to an Array1

  const input = 'CALX, [11.10.21 01:08]  $EGLD/USDT  #Ldfdfc  zone : 238.5 - 233  "LEVERAGE" : 3x TARGET1 : 243.9 TARGET 2 : 248 TARGET 3 : 254 TARGET 4 : 260 h.gd.s afca. `~!@#$%^&*()_-+=-/?><'

  const text = text.toUpperCase().match(/[a-z]+|\d+(?:\.\d+)?/gi);

so how can i change the Array1 to Array2?

sorry for my English and thank you for your help.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Based on the initial string, to get the desired array as output you don't have to convert it to an array to process it again.

You can use a pattern similar like the one that you tried with an alternation | but instead of matching [a-z]+ you can capture 1 or more non digits using (\D+) in a group.

Then in the callback of replace, you can remove the unwanted characters if there is a match for the group 1. The unwanted characters are [\W_]+ or one more non word chars including the underscore.

If there is no group, you can return the match (the digits) between delimiters, where you can split on the delimiters afterwards to create the final array.

const input = 'CALX, [11.10.21 01:08]  $EGLD/USDT  #Ldfdfc  zone : 238.5 - 233  "LEVERAGE" : 3x TARGET1 : 243.9 TARGET 2 : 248 TARGET 3 : 254 TARGET 4 : 260 h.gd.s afca. `~!@#$%^&*()_-+=-/?><'
text = input
  .toUpperCase()
  .replace(/\d+(?:\.\d+)?|(\D+)/g,
    (m, g1) => g1 ? g1.replace(/[\W_]+/g, '') : `#${m}#`
  );
console.log(text.split(/#+/));

about 4 years ago · Juan Pablo Isaza Denunciar

0

One of the solution could look like this:

let arr = [
    'CALX',  '11.10',  '21',
    '01',    '08',     'EGLD',
    'USDT',  'LDFDFC', 'ZONE',
    '238.5', '233',    'LEVERAGE',
    '3',     'X',      'TARGET',
    '1',     '243.9',  'TARGET',
    '2',     '248',    'TARGET',
    '3',     '254',    'TARGET',
    '4',     '260',    'H',
    'GD',    'S',      'AFCA'
]

function handleArray(a) {
    let result = [];
    let stringItem = '';

    a.forEach((el) => {
      // If number then check if we have previous string and push 
      // it to the result. 
      // Also push number as next element
        if (/\d/.test(el)) {
            if (stringItem) {
                result.push(stringItem);
                
                // Clear string variable
                stringItem = '';
            }
            result.push(el)
        } else {
            // Concat ongoing string, don't push to result
            stringItem += el;
        }
    })

    return result;
}

console.log(handleArray(arr))

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda