Skip to content

Instantly share code, notes, and snippets.

@nmquebb
Created April 1, 2020 09:59
Show Gist options
  • Select an option

  • Save nmquebb/b87094629bfb204f74685c20eaf58597 to your computer and use it in GitHub Desktop.

Select an option

Save nmquebb/b87094629bfb204f74685c20eaf58597 to your computer and use it in GitHub Desktop.
function createSentenceArray(str) {
const arr = str.split(" ");
const newArr = [];
for (let index = 0; index < arr.length; index++) {
const word = arr[index];
if (DO_YOUR_REGEX_THING) {
// if it is a mention push a span
newArr.push(<span>{word}</span>)
} else {
// if it isnt a mention comcatenate the last word
// we looped over add the next word to it
newArr(newArr[newArr.length] + " " + word)
}
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment