How to determine if one string starts with what another ends with

前端 未结 3 1242
一生所求
一生所求 2021-01-29 12:50

I have a list of phrases:

[
  \"according to all known laws of aviation\",
  \"time flies when you\'re having fun...\"
  ...
]

I would like to

3条回答
  •  深忆病人
    2021-01-29 13:15

    I converted the answer from the Python question into Javascript after doing some research on the Python language:

    function OverlapTest(input, compare) {
        for (var i = 0; i < input.length; i++) {
            if (compare.startsWith(input.substring(i))) {
                return true;
            }
        }
    
        return false;
    }
    

    This will return true if the strings overlap at the start and end and false if they don't.

提交回复
热议问题