Есть переменная [[LIST_WITH_FILE_CONTENT]] в ней много строчек.
Подскажите, как с помощью JS удалить в нём все строки что выше 3-рёх подряд идущих строк.
В конце этих 3-рёх строк должны стоять символы из списка [[SYMBOLS]] .
В списке [[SYMBOLS]] находятся знаки препинания:
. , ! ? " ' : ” “
Пример [[LIST_WITH_FILE_CONTENT]] :
Or to take arms against a sea of troubles?
And by opposing end them. To die—to sleep
No more; and by a sleep to say we end.
The heart-ache and the thousand natural shocks
That flesh is heir to: ’tis a consummation!
Devoutly to be wish’d. To die, to sleep;
To sleep, perchance to dream—ay, there’s the rub:
For in that sleep of death what dreams may come
Borne on the bier6 with white and bristly beard:
Then of thy beauty do I question make
Должно остаться так (выделил красной рамкой):

Написал JS-код для экшена Яваскрипт:
const str = [[LIST_WITH_FILE_CONTENT]];
const punct = [[SYMBOLS]];
const numStrWithPunctEnd = 3;
const arr = str.split('\n');
const index = arr.findIndex(function(n, i, a) {
return this.every(m => punct.includes(a[i + m].slice(-1)));
}, [...Array(numStrWithPunctEnd).keys()]);
const result = index !== -1 ? arr.slice(index).join('\n') : str;
[[LIST_WITH_FILE_CONTENT]]=result;
Но почему выдаёт ошибку:
