Testing: Javascript split content into by word count

by  @Arul on 01 May 2020, 15:57 GMT


const splitWords = (text, numWords) => {
  const words = text.split(' ')
  let part1 = '', part2 = ''
  words.forEach((word, idx) => {
    if (idx < numWords) {
       part1 += ' ' + word
    } else {
        part2 += ' ' + word 
    }
  })
  return [part1.trim(), part2.trim()]
}

const [ part1, part2 ] = splitWords(text, 25)
#1@akts on 01 May 2020, 15:59 GMT
Code formatting is on the future release plan @Arul Thanks for testing the app out Arulji.
1 of 1 1 replies