输入:
target: ["a", "b", "c", "d"]
sequence1: ["b", "c"]
sequence2: ["c", "b"]
期望的行为
sequence1 matches with target because "b", "c" matches with a sub sequence of the target
sequence2 does not match with target
我可以很容易地使用for循环在Python或Java中编写它。在scala中写这个的惯用方法是什么
答案 0 :(得分:2)
我认为containsSlice()
就是你所追求的目标。
scala> List("a","b","c","d").containsSlice(List("b","c"))
res0: Boolean = true
scala> List("a","b","c","d").containsSlice(List("c","b"))
res1: Boolean = false