title: Javascript: Splitting string without .split( ) method?
body: <p>In order to understand functions better I was advised to refactor the String.prototype.split() method. This isn't for school, I'm self-studying. I thought it was pretty straight forward but after four hours I'm disheartened that I'm not able to get this to work. Here's what I have so far:</p>
  
  <pre><code>var myString = "this is a sentence";
  var split = function(string, splitParameter) {
  var splitArray = [];
  var stringElement = "";
  var splitter = ""; 
  var j = 0;
  
  for (var i = 0; i &lt; string.length; i++) {
    if (string[i] !== splitParameter) {
        stringElement += string[i];
        splitArray[j] = stringElement;
    }else {
        j++;
        splitter += string[i];
    }
    return splitArray;
  }
  
  
  console.log(split(myString," "));
  </code></pre>
  
  <p>I'm having trouble figuring out what to do with the splitParameter argument. When I passed in " " as in the code I pasted above I get:</p>
  
  <pre><code>["this", "thisis", "thisisa", "thisisasentence"]
  </code></pre>
  
  <p>when I change the splitParameter to "" I get:</p>
  
  <pre><code>["this is a sentence"]
  </code></pre>
  
  <p>and when I pass in "t" I get: </p>
  
  <pre><code>[1: "his a sen", 2: "his is a senence"]
  </code></pre>
  
  <p>Can somebody help me get on the right track with what I'm doing? I'm trying to learn how to think about things functionally and use algorithmic reasoning and I can't make heads nor tails of what to do about the delimiter bit of the original split method. </p>
  
  <p>Thanks.</p>