Currently, I am working on an application that transforms lyrics into Google Slides by analyzing the number of line breaks between stanzas. To simplify the process, I have been repeatedly testing a specific set of lyrics. The procedure involves locating the position of the word 'foo' within the text and extracting a substring starting from the beginning up to that index in order to store it in an array. This array will later be utilized in generating slides through another function.
function splitLyrics(lyrics) {
var lyricsArray = [];
var lengthOfChunk = 0;
var lengthOfSong = 0;
var lyricsToPush;
while (lyrics.length > 0) {
Logger.log(lyrics);
lengthOfSong = lyrics.length;
lengthOfChunk = lyrics.indexOf('foo');
Logger.log(lengthOfChunk);
if (lengthOfChunk === -1) {
lengthOfChunk = lengthOfSong;
}
lyricsToPush = lyrics.substr(0, lengthOfChunk);
Logger.log(lyricsToPush);
lyricsArray.push(lyricsToPush);
lyrics = lyrics.substr(lengthOfChunk + 1);
}
return lyricsArray;
}
The expected outcome is to log "Original lyrics blah blah", followed by the index number, and then display the extracted substring such as "blah blah". However, the actual output logs "Original lyrics blah blah" first, then the index number, and finally repeats with "Original lyrics blah blah".