Skip to content

Instantly share code, notes, and snippets.

@vitalii-komenda
Created July 5, 2021 16:04
Show Gist options
  • Save vitalii-komenda/6ab43f90aacbab2903d474e3735e2d64 to your computer and use it in GitHub Desktop.
Save vitalii-komenda/6ab43f90aacbab2903d474e3735e2d64 to your computer and use it in GitHub Desktop.
isDevisible
isDevisible = (s, t) => {
let l = 0;
let r = 0;
let repStart = 0;
while(l < s.length) {
if (s[l] === t[r]) {
l++;
r++;
} else if (t[r] === undefined) {
repStart = r;
r = 0;
} else {
return -1;
}
}
if (repStart === 0) {
return l % r === 0 ? r : -1;
} else if (l % repStart === 0) {
return repStart;
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment