Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
how would I create a program that would sort text files like this in js

Lets say I have a text file structured like this:

Newborn adj. Recently born.

Newly adv. 1 recently. 2 afresh, anew.

New wave n. A style of rock music.

how would I separate the word and the definition in two different text files for the whole array so that I would have a words.txt file in javascript

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to separate each line of the text with the separators ["n.","adv.","adj." ...etc.] Look at your file to identify all of them, read the file line by line and use split() by one of these separators.

Demo:

const myText = `Newborn adj. Recently born.
Newly adv. 1 recently. 2 afresh, anew.
New wave n. A style of rock music.
`;

const getSeparator = (separators, target) => {
  for (const separator of separators) {
    if (target.includes(separator)) return separator;
  }
};

const separators = [`adj.`, `adv.`, `n.`];

for (const line of myText.split(`\n`)) {
  console.log(line);
  const separator = getSeparator(separators, line);
  const splitLines = line.split(separator).map((s) => s.trim());
  console.log(splitLines);
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda