Created
July 5, 2021 16:04
-
-
Save vitalii-komenda/6ab43f90aacbab2903d474e3735e2d64 to your computer and use it in GitHub Desktop.
isDevisible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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