function isRotation(s1, s2) {
const s3 = s1 + s1;
return typeof s1 === 'string' && typeof s2 === 'string' && s1.length === s2.length && isSubstring(s3, s2);
}
function isSubstring(s1, s2) {
return s1.indexOf(s2) !== -1;
}
function runTests(func) {
const inputOutput = [['foobarbaz', 'barbazfoo', true], ['', '', true], ['foo', '', false], ['', 'foo', false], [null, 'foo', false]];
for (let i = 0; i < inputOutput.length; i++) {
const input = inputOutput[i].slice(0, inputOutput[i].length-1);
const expected = inputOutput[i][inputOutput[i].length-1];
const result = func(...input);
if (result !== expected) {
return `Test failed: Expected - ${expected}. Got ${result}`;
}
}
return 'All tests passed!'
}
runTests(isRotation);