I am puzzled trying to work this one out.
1) I have a PHP array which is JSON_ENCODE to store in a JS array1.
2) Then a textarea, which the input is being split into a JS array2.
3) then compare both arrays and Slice & Concat with values from array1 deducted.
4) then take array2 and chunk it into arraySize of 50.
The issue I am facing is that I need the chunks of 50 to have a Semicolon seperating each value and another on the end of each chunk.
I have previously used a join, but the ';' gets added to the array and my arraySize gets messed up.
Any help is much appreciated.
//Store PHP values.
var ci_sites = <?echo json_encode($ci_pass);?>;
function dobuild(){
//Store textarea input into Array, Duplicates Removed.
var text = $("textarea#builder").val();
var lines = text.split(/\r\n|\s+\n|\s+\r|\n+|\r+/g);
var lines_arr = [];
$.each(lines,function(index, item){
if ($.inArray(item, lines_arr) ==-1)
lines_arr.push(item);
})
//Remove value from ci_sites.
var A1 = lines_arr;
var A2 = ci_sites;
for (var i = 0; i<A2.length; i++) {
var arrlen = A1.length;
for (var j = 0; j<arrlen; j++) {
if (A2[i] == A1[j]) {
A1 = A1.slice(0, j).concat(A1.slice(j+1, arrlen));
}
}
}
//Chunk The Array Into Sets Of 50.
var cleaned = A1;
var chunk = [];
var arraySize = 50;
for (var i = 0; i < Math.ceil(cleaned.length/arraySize); i++) {
chunk.push(cleaned.slice(i*arraySize,i*arraySize+arraySize));
var chunkbr = chunk.join("<br>");
$("#cleanlist").html("Cleaned CI's:<br><span style='color:#f00'>"+chunkbr+"</span>");
}*/
}`
@sly
The Values stored in ci_sites are:
111 222 333 444
The Values stored in lines_arr are:
111 222 333 444 555 666 777
The ouput will be:
555,666,777
The chunk.join is in the for as it breaks the Chunks into 50.