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

211
Views
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 answers
Answer question

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 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!