Trying to make a function that outputs a multiplication table given a maximum value.
My issue is that I have an array of arrays I need to join into a string, and no matter what I try, I can't get rid of the darn commas between each inner array item, please help me!
Here's my code:
var multiplicationTable = function(maxValue) {
var array = [];
var maxNum = maxValue ** 2;
y = 1;
var pad = ("+--" + "-".repeat(maxNum.toString().length - y.toString().length + 1)).repeat(maxValue) + "\+\n";
for (var i = 0; i <= maxValue * 2; i++) {
if (i % 2 != 0) {
array[i] = [];
for (var j = 0; j < maxValue; j++) {
var n = ((j + 1) * (i + 1)) / 2;
if (j + 1 == maxValue) {
array[i].push("| " + n.toString() + " ".repeat((maxNum).toString().length - n.toString().length + 1) + "|\n");
} else {
array[i].push("| " + n.toString() + " ".repeat((maxNum).toString().length - n.toString().length + 1));
}
};
} else {
array[i] = [pad];
}
}
return array.join(" ");
};
console.log(multiplicationTable(5));
console.log(multiplicationTable(10));