function endsWith(str, substr) { let ans = str.slice((str.length - substr.length), str.length); if (ans === substr) { return ans; } return 0; } s = "hello"; ans = endsWith(s, "llo"); console.log(ans);