JSFiddle - React, Tailwind, and code Playground

by emilcieslar

JavaScript

function newProgram(numberOfCharacters, text) {
  let characterCount = text.replace(/\s+/g, '').length;
  let noOfLineBreaks = Math.floor(characterCount / numberOfCharacters)
  //Find how to add variable to regex
  //Default noOfLineBreaks set as 40 in regex
  let regex = new RegExp(/(?<=^(?:.{25})+)(?!$)/)
  let splitText = text.split(regex)
  let addLineBreaks = splitText.map(string => `${string} \n`)
  let concatenateText = addLineBreaks.join("")
  console.log(concatenateText)
}

let lineOfText = "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. "

newProgram(25, lineOfText)