Tell us what’s happening:
I landed this solution, using a regex constructor. I was wondering if possible to translate that into a regex literal?? I couldn’t do it.
Your code so far
function confirmEnding(str, target) {
let strRegex = new RegExp(""+target+"$") // e. g. Why let strRegex = /"+target+"$/ doesn't work
let x = str.match(strRegex);
return str.match(strRegex) == target ? true : str.match(strRegex) != target ? false : false
}
console.log(confirmEnding("Open sesame", "same"))//true
console.log(confirmEnding("Connor", "n"))//false
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 OPR/62.0.3331.119
.
Link to the challenge: