Fix endsWith off-by-one error

This commit is contained in:
Richard Feldman 2022-07-22 10:54:21 -04:00 committed by Folkert
parent 7cf5732001
commit 6f1932eae4
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -897,9 +897,10 @@ endsWith : List elem, List elem -> Bool
endsWith = \list, suffix ->
# TODO once we have seamless slices, verify that this wouldn't
# have better performance with a function like List.compareSublists
start = List.len list - len
length = List.len suffix
start = Num.subSaturated (List.len list) length
suffix == List.sublist list { start, len: List.len suffix }
suffix == List.sublist list { start, len: length }
## Splits the list into two lists, around the given index.
##