By using this method , we can print the square matrix
with complexity less than n^2
xxxxxxxxxx
const getTemplate = (n) => {
let templateString = "";
for (let i=0; i<n; i++) {
console.log('iterating');
templateString += "${this.i++}\t";
}
return templateString;
}
const SquareMatrix = (n) => {
let template = getTemplate(n);
const obj = {
i: 0
};
let result = '';
for (let i=0; i<n; i++) {
console.log('iterating');
result += new Function("return "+template+"\n;").call(obj);
}
return result;
}
console.log(SquareMatrix(10))