js中如何检查从文件数据中读取的数组中数据的顺序

how to check the sequence of the data in an array read from a file data in js

我有一个包含 usfm 数据的文件 USFM_file_link,我用它制作了这个数组,每行只有标记

['id','c','p','v','p','v','v','v','p','v','v','v','v','p','v','v','v','v','p','v','v','v','c','p','v','p','v','v','v' ]

我想检查此文件每一行中标记的顺序。所以序列的条件是

Each chapter must have at least one \p marker before the first \v marker.

这意味着在 'c' 元素之后的第一个 'v' 元素需要一个 'p' 元素,除非文件格式不正确。以我的理解,我认为这是文本解析,但不知道如何检查这个问题的顺序。任何帮助,将不胜感激。我不是在请求帮助我编码,而是在读取和解析这样的文件时如何检查 JavaScript 中的顺序的逻辑。

var list = ['id', 'c', 'p', 'v', 'p', 'v', 'v', 'v', 'p', 'v', 'v', 'v', 'v', 'p', 'v', 'v', 'v', 'v', 'p', 'v', 'v', 'v', 'c', 'p', 'v', 'p', 'v', 'v', 'v'];

if (isPatternFound(list, "c", "v", "p")) {
    console.log("Found")
} else {
    console.log("Not found")
}

function isPatternFound(inputList, startValue, followedValue, followedByValue) {
    var cIdx = inputList.indexOf(startValue), isFound=false;
    while (cIdx > -1) {
        inputList.splice(0, inputList.indexOf(startValue));
        inputList.splice(0, inputList.indexOf(followedValue));
        if (inputList[1] == followedByValue) {
            isFound= true;
            return isFound;
        } else {
            isFound= false;
        }
        cIdx = inputList.indexOf(startValue);
    }
    return isFound;
};