Using RegEx would be one way, but if you are fine with using string methods I was able to solve the challenge in one line using the slice method. Is there a reason you’d like not to use string methods?
Because the freecodecamp in its current curriculum has not taught it so far. I would like to wait until later sections when they teach it to start using it.
Regex has been taught so asking, how would you do it using regex? Can you just give me an idea and not the code. (Paused here for a while and gave a hard thought lol)
Oh I think I remember now , you just make a regex out of the target value and you search for it right. Holy shit, would’ve been so easy that is a few lines. Thanks for the suggestion! Happy to recall it!
hi i made this solution of only utilizing a for loop, string indexing and length.
function confirmEnding(str, target) {
let targetL=target.length
let strL=str.length
let end=''
for (let i=strL-targetL; i<strL; i++){
end+=str[i]
}
return end===target
}
PS: you can directly use the str.length values instead of assigning them to variables and shorten the code even more
Im afraid to use regex to solve the challenge, you will need to use the RegExp object and include the target value in the RegExp body, which is not a technique part of the curriculum.