fix formatting of Spiralize Matrix contract

This commit is contained in:
Olivier Gagnon
2021-09-04 19:54:08 -04:00
parent 05bab22807
commit 05a6f2a20e
7 changed files with 835 additions and 808 deletions

View File

@@ -152,23 +152,34 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"Given the following array of array of numbers representing a 2D matrix,",
"return the elements of the matrix as an array in spiral order:\n\n",
].join(" ");
for (const line of n) {
d += `${line.toString()},\n`;
}
// for (const line of n) {
// d += `${line.toString()},\n`;
// }
d += "    [\n";
d += n
.map(
(line: number[]) =>
"        [" +
line.map((x: number) => `${x}`.padStart(2, " ")).join(",") +
"]",
)
.join("\n");
d += "\n    ]\n";
d += [
"\nHere is an example of what spiral order should be:",
"\nExample:",
"\nHere is an example of what spiral order should be:\n\n",
"    [\n",
"        [1, 2, 3],\n",
"        [4, 5, 6],\n",
"        [1, 2, 3]\n",
"        [4, 5, 6]\n",
"        [7, 8, 9]\n",
"    ] should result in [1, 2, 3, 6, 9, 8 ,7, 4, 5]\n\n",
"Note that the matrix will not always be square:\n",
"    ]\n\n",
"Answer: [1, 2, 3, 6, 9, 8 ,7, 4, 5]\n\n",
"Note that the matrix will not always be square:\n\n",
"    [\n",
"        [1, 2, 3, 4]\n",
"        [5, 6, 7, 8]\n",
"        [9, 10, 11, 12]\n",
"    ] should result in [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7",
"        [1,  2,  3,  4]\n",
"        [5,  6,  7,  8]\n",
"        [9, 10, 11, 12]\n",
"    ]\n\n",
"Answer: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]",
].join(" ");
return d;