title: Convert different strings to snake_case in Javascript
body: <p>I know that we have a question similar to this but not quite the same. 
  I'm trying to make my function work which takes in a string as an argument and converts it to snake_case . It works most of the time with all the fancy <code>!?&lt;&gt;=</code> characters but there is one case that it can't convert and its camelCase .</p>
  
  <p>It fails when I'm passing strings like <code>snakeCase</code>. It returns <code>snakecase</code> instead of <code>snake_case</code>.</p>
  
  <p>I tried to implement it but I ended up just messing it up even more.. </p>
  
  <p>Can I have some help please?</p>
  
  <p>my code: </p>
  
  <pre><code>const snakeCase = string =&gt; {
      string = string.replace(/\W+/g, " ").toLowerCase().split(' ').join('_');
  
      if (string.charAt(string.length - 1) === '_') {
          return string.substring(0, string.length - 1);
      }
  
      return string;
  }
  </code></pre>