title: Broken Sequence javascript
body: <p>I am doing a kata from Codewars, and I can not pass 2 test. It is almost there but still missing something. This function must return what is missing from a broken  sequence. These are the instructions:</p>
  
  <p><strong><em>"Find out the missing number; if the sequence is not broken, you should return 0. Each sequence always increments by 1.
  In short: an invalid sequence (a string with non numeric character) must return 1, an already complete (or empty) sequence must return 0; a broken sequence with more than one number missing should return the lowest missing number; otherwise return the missing number."</em></strong></p>
  
  <p>This is the link:<a href="http://www.codewars.com/kata/broken-sequence/java" rel="nofollow noreferrer">http://www.codewars.com/kata/broken-sequence/java</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function findMissingNumber(sequence) {
    var max = sequence.slice(-1);
    var min = sequence[0];
    var RegExp = /[abcdefghijklmopqrstuvwxyz]/i;
    
    for (var j = 0; j &lt; sequence.length; j++) {
      if (sequence.charAt(j).match(RegExp)) {
        return 1;
      }
    } //loop
  
    if (sequence === " " || sequence.length == 0) {
      return 0;
    }
    //
    else {
      sequence = sequence.split(" ").sort().map(function number(value) {
        return parseInt(value);
      });
  
      var numbers = [];
  
      for (var i = 1; i &lt;= max; i++) {
        numbers.push(i);
      } //loop
  
      if (sequence[0] != numbers[0]) {
        return numbers[0];
      } else if (sequence[1] != numbers[1]) {
        return numbers[1];
      } else {
        var totala = sequence.reduce(function(a, b) {
          return a + b
        });
        var totalb = numbers.reduce(function(a, b) {
          return a + b
        });
        return Math.abs(totala - totalb);
      }
    } //main else
  } //end
  console.log(findMissingNumber(""));</code></pre>
  </div>
  </div>
  </p>