we can iterate just once!
This commit is contained in:
parent
9e99375349
commit
e7e1b615ff
12
04/index.ts
12
04/index.ts
@ -17,16 +17,12 @@ console.log(
|
|||||||
.reduce(
|
.reduce(
|
||||||
(coll, curr, index, array) => {
|
(coll, curr, index, array) => {
|
||||||
// 2D string matching is a pain. Let's turn it into a 1D problem!
|
// 2D string matching is a pain. Let's turn it into a 1D problem!
|
||||||
// create the columns
|
|
||||||
curr.split("").forEach((s, i) => {
|
curr.split("").forEach((s, i) => {
|
||||||
|
// create the columns
|
||||||
coll[i] += s;
|
coll[i] += s;
|
||||||
});
|
// create the left-diagonals
|
||||||
// create the down-left-diagonals
|
coll[array.length + index + i] += s;
|
||||||
curr.split("").forEach((s, i) => {
|
// create the right-diagonals
|
||||||
coll[i + array.length + index] += s;
|
|
||||||
});
|
|
||||||
// create the down-right-diagonals
|
|
||||||
curr.split("").forEach((s, i) => {
|
|
||||||
coll[array.length * 4 + index - i - 2] += s;
|
coll[array.length * 4 + index - i - 2] += s;
|
||||||
});
|
});
|
||||||
// include the original row
|
// include the original row
|
||||||
|
Loading…
Reference in New Issue
Block a user