I'm trying to create a game similar to a crossword. I am storing my letters into this array. Can I please have some help extracting the words from this 2D array of mine?
let testArr = [
["T", " ", " ", " "],
["E", "A", "R", " "],
["S", " ", " ", " "],
["T", " ", " ", " "]
];
let storeWords = [];
function loop() {
let storeRowLetters = [];
let storeColLetters = [];
for (let col = 0; col < testArr.length; col++) {
for (let row = 0; row < testArr[col].length; row++) {
console.log(testArr[row][col])
storeColLetters.push(testArr[row][col]);
}
}
console.log("Next output scans the row")
for (let col = 0; col < testArr.length; col++) {
for (let row = 0; row < testArr[col].length; row++) {
console.log(testArr[col][row])
storeRowLetters.push(testArr[col][row]);
}
}
console.log(storeColLetters.join(''))
console.log(storeRowLetters.join(''))
}
loop()
The outputs I receive from the console log are
From the last 2 lines of my picture, I would like to extract the word TEST
from the string of TEST A R
and EAR
from T EAR S T
. So basically I would like to discard the letters that are on their own. After acquiring the words, I would like to push them to my array of storeWords
.