32. Trailing String
You are given two strings 'A' and 'B'. Print out a 1 if string 'B' occurs at the end of string 'A'. Else a zero. Input sample: The first argument is a file, containing two strings, comma delimited, one per line. Ignore all empty lines in the input file.e.g. Hello World,World Hello CodeEval,CodeEval San Francisco,San Jose Output sample: Print out 1 if the second string occurs at the end of the first string. Else zero. Do NOT print out empty lines between your output. e.g. 110
by Donal Devine
HTML
<div id="divConsole"></div>
CSS
.console-output
{
font-family: monospace;
margin: 1px;
}
JavaScript
console = {
log: function (s) {
divConsole.innerHTML +=
"<p class=\"console-output\">" + s + "</p>";
}
};
var foo = function(s) {
var a = s.split(',');
return a[0].lastIndexOf(a[1]) == a[0].length - a[1].length ? 1 : 0;
};
console.log(foo("Hello World,World"));
console.log(foo("Hello CodeEval,CodeEval"));
console.log(foo("San Francisco,San Jose"));