JavaScript - String.match() method
Approach\n1. Find first substring without letter \'a\'\n2. Replace each letter of that substring with preceding letter\n\nIn case string only consists of letter
# Approach\n1. Find first substring without letter `\'a\'`\n2. Replace each letter of that substring with preceding letter\n\nIn case string only consists of letters `\'a\'`, replace last `\'a\'` with `\'z\'`. \n\n# Code\n```\n/**\n * @param {string} s\n * @return {string}\n */\nvar smallestString = function(s) {\n    // Get first substring without letter \'a\'\n    const substrData = s.match(\'[b-z]+\');\n    \n    // Replace last \'a\' with \'z\' in case string only consists of letters \'a\' and return\n    if(substrData == null) {\n        return s.slice(0,s.length-1) + \'z\';\n    }\n\n    const substr = substrData[0];\n    const substrIdx = substrData.index;\n    const prefix = s.slice(0,substrIdx);\n    const suffix = s.slice(substrIdx + substr.length, s.length);\n    let substrConverted = \'\';\n \n    // Replace each letter of substring with preceding letter\n    for(let i=0; i<substr.length; i++) {\n        substrConverted = substrConverted + String.fromCharCode(substr.charCodeAt(i)-1);\n    }\n    \n    // Concatenate prefix, converted substring and suffix and return result\n    return prefix + substrConverted + suffix;\n};\n```
['JavaScript']