search end string in another string my solution
parent
5e1cc1b0ef
commit
19a5845d20
@ -0,0 +1,10 @@
|
|||||||
|
function solution1(str: string, ending: string): boolean {
|
||||||
|
if (ending === "") return true;
|
||||||
|
const startIndex = str.length - ending.length;
|
||||||
|
const subStr = str.substring(startIndex);
|
||||||
|
return subStr === ending;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(solution1("abcde", "cde"), true);
|
||||||
|
console.log(solution1("abcde", "abs"), false);
|
||||||
|
console.log(solution1("abcde", ""), true);
|
||||||
Loading…
Reference in New Issue