another implementation 'endsWith' function