JSFiddle - React, Tailwind, and code Playground

by emilcieslar

JavaScript

const spaceRegexp = /\s+/;
const wordDenerator = w => {
  return textLines => {
    const result = [];
    let counter = 0;

    while (counter <= textLines.length - 1) {
      const line = textLines[counter].split(spaceRegexp);
      const resultLine = line.filter(token => token.length === w);

      if (
        resultLine.length
        /* not sure that understand properly
        but if we want check length of words
        in output line, uncomment next line
        */

        // && resultLine.length > 1
      ) {
        result.push(resultLine.join(" "));
      }

      counter++;
    }

    return result;
  };
};

/* 'What the fuck'

resultLine = ['What'] */

const result = wordDenerator(15)([
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
'It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.',
]);
debugger