This is a nice exercise on slices, and also careful reasoning about string length comparisons. A good warmup. Javascript doesn’t have slices, not in this nice syntax.
def solution(string, ending):
if len(ending) > len(string):
return False
start = len(string) - len(ending)
return string[start:] == ending