title: camelCase to kebab-case
body: <p>I have a kebabize function which converts camelCase to kebab-case. I am sharing my code. Can it be more optimized? I know this problem can be solved using regex. But, I want to do it without using regex.</p>
  <pre><code>const kebabize = str =&gt; {
  
      let subs = []
      let char = ''
      let j = 0
  
      for( let i = 0; i &lt; str.length; i++ ) {
  
          char = str[i]
  
          if(str[i] === char.toUpperCase()) {
              subs.push(str.slice(j, i))
              j = i
          }
  
          if(i == str.length - 1) {
              subs.push(str.slice(j, str.length))
          }
      }
  
      return subs.map(el =&gt; (el.charAt(0).toLowerCase() + el.substr(1, el.length))).join('-')
  }
  
  kebabize('myNameIsStack')
  </code></pre>