Beginner here. I've got a text area. I want to break the text up into a matrix and then transpose rows and columns. I've got function that splits the text into groups. another function that puts them into an array and that's as far as I've got. I don't really know how to combine them into one function or if that is needed. i believe i'm supposed convert the array into a matrix by creating sub arrays, then i can finally transpose the text from [ i ][ j ] to [ j ][ i ]. Is this right so far or have i left something out? I'd love to see a working example someplace but can't seem to find one.
function G_Group(size, count)
{
if (size <= 0)
{
size = document.encoder.group_size.value;
if (size <= 0)
{
alert('Invalid group size');
return false;
}
}
if (count <= 0)
{
count = document.encoder.group_count.value;
if (count <= 0)
{
alert('Invalid group count');
return false;
}
}
var t = document.encoder.text.value;
var o = '', groups = 0;
t = Tr(t, " \r\n\t");
while (t.length > 0)
{
if (o.length > 0)
{
o += ' ';
}
if (groups >= count)
{
o += "\n";
groups = 0;
}
groups ++;
o += t.slice(0, size);
t = t.slice(size, t.length);
}
document.encoder.text.value = o;
return false;
}
function toArray()
{
var str = document.encoder.text.value;
var nstr = str.split(" ");
document.encoder.text.value = nstr;
}
//i am having trouble with this part. don't know how to call the document.encoder.text.value into the list and don't know how to call group_size into elementsPerSubArray
function toMatrix(list, elementsPerSubArray) {
var matrix = [], i, k;
for (i = 0, k = -1; i < list.length; i++) {
if (i % elementsPerSubArray === 0) {
k++;
matrix[k] = [];
}
matrix[k].push(list[i]);
}
return matrix;
}
Finally, i don't know how to post result back into the textarea
So far i can group the text into block of how many characters i choose from a selection box (i've got 30 options) and can make line breaks wherever i want. as far as the matrix goes, line breaks will be made after 1 group of (X) characters. Given this text:
OOMUCHABOUTMYCOUNTRYICAREALOTH
I can break it into groups like this.
OOMUC HABOU TMYCO UNTRY ICARE ALOTH
or like this if i want.
OOMUC
HABOU
TMYCO
UNTRY
ICARE
ALOTH
What i want to do is be able to flip the matrix so it looks like this
AIUTHO
LCNMAO
...ect
HEYOUC