1/**2* @param {string} s3* @param {character} c4* @return {number[]}5*/6var shortestToChar = function (s, c) {7let result = [];89for (let i = 0; i < s.length; i++) {10if (s.charAt(i) === c) result.push(0);11else {12const next = s.indexOf(c, i) === -1 ? Infinity : s.indexOf(c, i) - i;13const prev =14result.lastIndexOf(0) === -1 ? Infinity : i - result.lastIndexOf(0);15result.push(Math.min(next, prev));16}17}1819return result;20};