문제 링크 : Shortest Distance to Target String in a Circular Array
/**
* @param {string[]} words
* @param {string} target
* @param {number} startIndex
* @return {number}
*/
var closetTarget = function(words, target, startIndex) {
let left = startIndex
let right = startIndex
let step = 0
let n = words.length
while(step <= n) {
if(words[left] === target || words[right] === target) {
return step
} else {
right = (right + 1) % n
left = (left -1 + n) % n
}
step++
}
return -1
};