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:
string 123543512
searching for 2
-digit sequences
duplicates "12","35"
splitedstring 12 35 4 35 12
var n = 2;
var a = 0;
var b = n;
var arr =[];
function newText(input) {
var str1 = textfield.value(); //given string
while (a <= str1.length & b < 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 < arr.length - 1; i++) {
if (potnij[i + 1] == potnij[i]) {
takisam.push(potnij[i]);
}
}
console.log(takisam);
}
Your first stop should be the P5.js reference.
Specifically, the
splitTokens()
function does exactly what you describe. You give it a string and then a list of tokens (substrings) to split on, and it returns an array of strings that were separated by those tokens.