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(
|
||||
(coll, curr, index, array) => {
|
||||
// 2D string matching is a pain. Let's turn it into a 1D problem!
|
||||
curr.split("").forEach((s, i) => {
|
||||
// create the columns
|
||||
curr.split("").forEach((s, i) => {
|
||||
coll[i] += s;
|
||||
});
|
||||
// create the down-left-diagonals
|
||||
curr.split("").forEach((s, i) => {
|
||||
coll[i + array.length + index] += s;
|
||||
});
|
||||
// create the down-right-diagonals
|
||||
curr.split("").forEach((s, i) => {
|
||||
// create the left-diagonals
|
||||
coll[array.length + index + i] += s;
|
||||
// create the right-diagonals
|
||||
coll[array.length * 4 + index - i - 2] += s;
|
||||
});
|
||||
// include the original row
|
||||
|
Loading…
Reference in New Issue
Block a user