title: How to split string on substrings determined by function p5.js
body: <p>I managed to find all n-digit sequence that repeat in a given digit string. Though my problem is how do i split the string on the repeated sequences, as shown on this example:</p>
  
  <p><p>string <code>123543512</code>
  <p>searching for <code>2</code>-digit sequences
  <p>duplicates <code>"12","35"</code>
  <p>splitedstring <code>12 35 4 35 12</code></p>
  
  <pre><code>    var n = 2; 
      var a = 0;
      var b = n;
      var arr =[];
  
      function newText(input) {
        var str1 = textfield.value(); //given string
        while (a &lt;= str1.length &amp; b &lt; str1.length+1) { 
          res = str1.substring(b, a);
          arr[a]=res;
          push();
          a = a + 1
          b = b + 1
        }         
          var potnij = arr.slice().sort();
          var takisam = []; //duplicates
          for (var i = 0; i &lt; arr.length - 1; i++) {
              if (potnij[i + 1] == potnij[i]) {
                  takisam.push(potnij[i]);
              }
          }
          console.log(takisam);
          }
  </code></pre>