I'm trying to write a regexp which should return true if a given string foo ends with the given string bar. E.g:
function solution(str, ending)
{
var pattern = "/" + ending + "$/";
var regex = new RegExp(pattern, "i");
console.log( str + ", " + ending + " , " + regex.source);
return regex.test(str);
}
However, if I test this using the following input:
console.log( solution("samurai", "ai") );
I get the following console output:
samurai, ai , /ai$/
false
The pattern seems correct to me, so why is it returning false for 'samurai' ending with 'ai' ?